Skip to content

Commit

Permalink
Add a prelude to make the method traits easier to import
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Mar 25, 2024
1 parent 63de229 commit 2876f58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
/// # Example
///
/// ```
/// use numpy::{PyArray3, PyArrayMethods, PyUntypedArrayMethods};
/// use numpy::prelude::*;
/// use numpy::PyArray3;
/// use pyo3::Python;
///
/// Python::with_gil(|py| {
Expand Down Expand Up @@ -1329,7 +1330,8 @@ impl<T: Element, D> PyArray<T, D> {
/// # Example
///
/// ```
/// use numpy::{PyArray, PyArrayMethods, PyUntypedArrayMethods};
/// use numpy::prelude::*;
/// use numpy::PyArray;
/// use pyo3::Python;
///
/// Python::with_gil(|py| {
Expand Down Expand Up @@ -1846,8 +1848,8 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {

/// Extends or truncates the dimensions of an array.
///
/// This method works only on [contiguous][PyUntypedArray::is_contiguous] arrays.
/// Missing elements will be initialized as if calling [`zeros`][Self::zeros].
/// This method works only on [contiguous][PyUntypedArrayMethods::is_contiguous] arrays.
/// Missing elements will be initialized as if calling [`zeros`][PyArray::zeros_bound].
///
/// See also [`ndarray.resize`][ndarray-resize] and [`PyArray_Resize`][PyArray_Resize].
///
Expand All @@ -1859,7 +1861,8 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
/// # Example
///
/// ```
/// use numpy::{PyArray, PyArrayMethods, PyUntypedArrayMethods};
/// use numpy::prelude::*;
/// use numpy::PyArray;
/// use pyo3::Python;
///
/// Python::with_gil(|py| {
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ pub use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};

pub use ndarray::{array, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn};

/// A prelude
///
/// The purpose of this module is to avoid direct imports of
/// the method traits defined by this crate via a glob import:
///
/// ```
/// # #![allow(unused_imports)]
/// use numpy::prelude::*;
/// ```
pub mod prelude {
pub use crate::array::{PyArray0Methods, PyArrayMethods};
pub use crate::dtype::PyArrayDescrMethods;
pub use crate::untyped_array::PyUntypedArrayMethods;
}

#[cfg(doctest)]
mod doctest {
macro_rules! doc_comment {
Expand Down

0 comments on commit 2876f58

Please sign in to comment.