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 {
177177
178178 /// Returns dtype for the base element of subarrays, regardless of their dimension or shape.
179179 ///
180+ /// If the dtype is not a subarray, returns self.
181+ ///
180182 /// 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 {
182184 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+ }
184190 }
185- Some ( unsafe { Self :: from_borrowed_ptr ( self . py ( ) , ( * self . as_dtype_ptr ( ) ) . subarray as _ ) } )
186191 }
187192
188193 /// 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