py: boolean-mask keys raise NotImplementedError, not TypeError
h5py supports boolean masks for reads and writes; clawhdf5 supports neither, so a mask is an unsupported operation (NotImplementedError, as for every other edit the bindings cannot do), not an invalid key. Tests: test_unsupported_edits_are_clear_errors (1-D, N-D and per-axis mask writes, file unchanged) and test_boolean_masks_are_refused (reads). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
//! (negative from the end) drop their axis, slices must have a positive
|
||||
//! step, one `Ellipsis` fills the unmentioned axes, a single increasing list
|
||||
//! of integers may index one axis, and strings name compound fields.
|
||||
//! Everything else (`None`/`np.newaxis`, boolean masks, several index lists)
|
||||
//! is refused with the error h5py gives.
|
||||
//! Everything else (`None`/`np.newaxis`, several index lists) is refused
|
||||
//! with the error h5py gives; boolean masks, which h5py supports, raise
|
||||
//! `NotImplementedError`.
|
||||
|
||||
use clawhdf5_format::selection::Selection;
|
||||
use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
|
||||
use pyo3::exceptions::{PyIndexError, PyNotImplementedError, PyTypeError, PyValueError};
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{PyEllipsis, PySlice, PyString, PyTuple};
|
||||
|
||||
@@ -379,8 +380,10 @@ fn parse_axis(py: Python<'_>, a: &Bound<'_, PyAny>, n: u64) -> PyResult<Axis> {
|
||||
let arr = np.call_method1("asarray", (a,))?;
|
||||
let kind: String = arr.getattr("dtype")?.getattr("kind")?.extract()?;
|
||||
if kind == "b" {
|
||||
return Err(PyTypeError::new_err(
|
||||
"Boolean mask indexing is not supported by clawhdf5",
|
||||
// h5py supports masks; clawhdf5 does not (yet), for reads or
|
||||
// writes: an unsupported operation, not a wrong key.
|
||||
return Err(PyNotImplementedError::new_err(
|
||||
"boolean mask indexing is not supported by clawhdf5",
|
||||
));
|
||||
}
|
||||
let ndim: usize = arr.getattr("ndim")?.extract()?;
|
||||
|
||||
Reference in New Issue
Block a user