fix(py): a 0-d integer array indexes like an int
ds[np.array(1)] went down the index-list path, where tolist() returns a scalar and extracting a list of indices raised a confusing TypeError. h5py treats it as an integer index; so do we now. The h5py comparison keys include 0-d arrays (signed and unsigned) on each axis; they failed before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -361,6 +361,14 @@ fn parse_axis(py: Python<'_>, a: &Bound<'_, PyAny>, n: u64) -> PyResult<Axis> {
|
||||
let is_array_like = a.is_instance(&np.getattr("ndarray")?)?
|
||||
|| a.is_instance_of::<pyo3::types::PyList>()
|
||||
|| a.is_instance_of::<PyTuple>();
|
||||
// A 0-d integer array (`ds[np.array(1)]`) is an integer index, as in h5py.
|
||||
if a.is_instance(&np.getattr("ndarray")?)? && a.getattr("ndim")?.extract::<usize>()? == 0 {
|
||||
let kind: String = a.getattr("dtype")?.getattr("kind")?.extract()?;
|
||||
if kind == "i" || kind == "u" {
|
||||
let i: i128 = a.call_method0("item")?.extract()?;
|
||||
return Ok(Axis::Index(normalize(i, n)?));
|
||||
}
|
||||
}
|
||||
if !is_bool && !is_array_like && a.hasattr("__index__")? {
|
||||
let i: i128 = a.call_method0("__index__")?.extract()?;
|
||||
return Ok(Axis::Index(normalize(i, n)?));
|
||||
|
||||
Reference in New Issue
Block a user