File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -177,12 +177,17 @@ impl PyArrayDescr {
177
177
178
178
/// Returns dtype for the base element of subarrays, regardless of their dimension or shape.
179
179
///
180
+ /// If the dtype is not a subarray, returns self.
181
+ ///
180
182
/// Equivalent to [`np.dtype.base`](https://numpy.org/doc/stable/reference/generated/numpy.dtype.base.html).
181
- pub fn base ( & self ) -> Option < & PyArrayDescr > {
183
+ pub fn base ( & self ) -> & PyArrayDescr {
182
184
if !self . has_subarray ( ) {
183
- return None ;
185
+ self
186
+ } else {
187
+ unsafe {
188
+ Self :: from_borrowed_ptr ( self . py ( ) , ( * ( * self . as_dtype_ptr ( ) ) . subarray ) . base as _ )
189
+ }
184
190
}
185
- Some ( unsafe { Self :: from_borrowed_ptr ( self . py ( ) , ( * self . as_dtype_ptr ( ) ) . subarray as _ ) } )
186
191
}
187
192
188
193
/// Returns shape tuple of the sub-array if this dtype is a sub-array, and `None` otherwise.
You can’t perform that action at this time.
0 commit comments