Skip to content

Commit 2b42e2a

Browse files
committed
Add a prelude to make the method traits easier to import
1 parent 63de229 commit 2b42e2a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/array.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
326326
/// # Example
327327
///
328328
/// ```
329-
/// use numpy::{PyArray3, PyArrayMethods, PyUntypedArrayMethods};
329+
/// use numpy::prelude::*;
330+
/// use numpy::PyArray3;
330331
/// use pyo3::Python;
331332
///
332333
/// Python::with_gil(|py| {
@@ -1329,7 +1330,8 @@ impl<T: Element, D> PyArray<T, D> {
13291330
/// # Example
13301331
///
13311332
/// ```
1332-
/// use numpy::{PyArray, PyArrayMethods, PyUntypedArrayMethods};
1333+
/// use numpy::prelude::*;
1334+
/// use numpy::PyArray;
13331335
/// use pyo3::Python;
13341336
///
13351337
/// Python::with_gil(|py| {
@@ -1847,7 +1849,7 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
18471849
/// Extends or truncates the dimensions of an array.
18481850
///
18491851
/// This method works only on [contiguous][PyUntypedArray::is_contiguous] arrays.
1850-
/// Missing elements will be initialized as if calling [`zeros`][Self::zeros].
1852+
/// Missing elements will be initialized as if calling [`zeros`][PyArray::zeros].
18511853
///
18521854
/// See also [`ndarray.resize`][ndarray-resize] and [`PyArray_Resize`][PyArray_Resize].
18531855
///
@@ -1859,7 +1861,8 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
18591861
/// # Example
18601862
///
18611863
/// ```
1862-
/// use numpy::{PyArray, PyArrayMethods, PyUntypedArrayMethods};
1864+
/// use numpy::prelude::*;
1865+
/// use numpy::PyArray;
18631866
/// use pyo3::Python;
18641867
///
18651868
/// Python::with_gil(|py| {

src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ pub use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
119119

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

122+
/// A prelude
123+
///
124+
/// The purpose of this module is to avoid direct imports of
125+
/// the method traits defined by this crate via a glob import:
126+
///
127+
/// ```
128+
/// # #![allow(unused_imports)]
129+
/// use numpy::prelude::*;
130+
/// ```
131+
pub mod prelude {
132+
pub use crate::array::{PyArray0Methods, PyArrayMethods};
133+
pub use crate::dtype::PyArrayDescrMethods;
134+
pub use crate::untyped_array::PyUntypedArrayMethods;
135+
}
136+
122137
#[cfg(doctest)]
123138
mod doctest {
124139
macro_rules! doc_comment {

0 commit comments

Comments
 (0)