Skip to content

Commit 853117d

Browse files
committed
Fix in behaviour of PyArrayDescr::base
1 parent a9228d4 commit 853117d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/dtype.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)