Skip to content

Commit 9a8c376

Browse files
committed
PyArrayDescr::get_type -> typeobj + fix docs
1 parent 1ec6e0d commit 9a8c376

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/dtype.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,6 @@ impl PyArrayDescr {
6868
self.into_ptr() as _
6969
}
7070

71-
/// Returns the internal `PyType` that this `dtype` holds.
72-
///
73-
/// # Example
74-
/// ```
75-
/// pyo3::Python::with_gil(|py| {
76-
/// let array = numpy::PyArray::from_vec(py, vec![0.0, 1.0, 2.0f64]);
77-
/// let dtype = array.dtype();
78-
/// assert_eq!(dtype.get_type().name().unwrap().to_string(), "float64");
79-
/// });
80-
/// ```
81-
pub fn get_type(&self) -> &PyType {
82-
let dtype_type_ptr = unsafe { *self.as_dtype_ptr() }.typeobj;
83-
unsafe { PyType::from_type_ptr(self.py(), dtype_type_ptr) }
84-
}
85-
8671
/// Shortcut for creating a descriptor of 'object' type.
8772
pub fn object(py: Python) -> &Self {
8873
Self::from_npy_type(py, NPY_TYPES::NPY_OBJECT)
@@ -105,6 +90,16 @@ impl PyArrayDescr {
10590
}
10691
}
10792

93+
/// Returns the
94+
/// [array scalar](https://numpy.org/doc/stable/reference/arrays.scalars.html)
95+
/// corresponding to this dtype.
96+
///
97+
/// Equivalent to [`np.dtype.type`](https://numpy.org/doc/stable/reference/generated/numpy.dtype.type.html).
98+
pub fn typeobj(&self) -> &PyType {
99+
let dtype_type_ptr = unsafe { *self.as_dtype_ptr() }.typeobj;
100+
unsafe { PyType::from_type_ptr(self.py(), dtype_type_ptr) }
101+
}
102+
108103
/// Returns a unique number for each of the 21 different built-in
109104
/// [enumerated types](https://numpy.org/doc/stable/reference/c-api/dtype.html#enumerated-types).
110105
///
@@ -455,7 +450,7 @@ mod tests {
455450
#[test]
456451
fn test_dtype_names() {
457452
fn type_name<T: Element>(py: pyo3::Python) -> &str {
458-
dtype::<T>(py).get_type().name().unwrap()
453+
dtype::<T>(py).typeobj().name().unwrap()
459454
}
460455
pyo3::Python::with_gil(|py| {
461456
assert_eq!(type_name::<bool>(py), "bool_");

0 commit comments

Comments
 (0)