@@ -68,21 +68,6 @@ impl PyArrayDescr {
68
68
self . into_ptr ( ) as _
69
69
}
70
70
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
-
86
71
/// Shortcut for creating a descriptor of 'object' type.
87
72
pub fn object ( py : Python ) -> & Self {
88
73
Self :: from_npy_type ( py, NPY_TYPES :: NPY_OBJECT )
@@ -105,6 +90,16 @@ impl PyArrayDescr {
105
90
}
106
91
}
107
92
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
+
108
103
/// Returns a unique number for each of the 21 different built-in
109
104
/// [enumerated types](https://numpy.org/doc/stable/reference/c-api/dtype.html#enumerated-types).
110
105
///
@@ -455,7 +450,7 @@ mod tests {
455
450
#[ test]
456
451
fn test_dtype_names ( ) {
457
452
fn type_name < T : Element > ( py : pyo3:: Python ) -> & str {
458
- dtype :: < T > ( py) . get_type ( ) . name ( ) . unwrap ( )
453
+ dtype :: < T > ( py) . typeobj ( ) . name ( ) . unwrap ( )
459
454
}
460
455
pyo3:: Python :: with_gil ( |py| {
461
456
assert_eq ! ( type_name:: <bool >( py) , "bool_" ) ;
0 commit comments