The fancy indexing using a mix of NumPy boolean array and an explicit list does not seem to work in the latest h5py version 3.1.0. The detailed trackback is shown at the bottom.
The exact same commands work in h5py version 2.10.
In h5py version 3.1.0, fancy indexing using NumPy boolean array only or using explicit lists only also works.
To assist reproducing bugs, please include the following:
```python
(insar) yunjunz:~>$ python
Python 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 02:37:09)
[Clang 10.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import numpy as np
import h5py
arr = np.arange(100).reshape((10,10))
with h5py.File('test.h5', 'w') as f:
... dset = f.create_dataset("MyDataset", data=arr)
... result = dset[arr[:,0] > 20, :]
... result.shape
...
Traceback (most recent call last):
File "", line 3, in
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "/Users/yunjunz/tools/miniconda3/envs/insar/lib/python3.7/site-packages/h5py/_hl/dataset.py", line 777, in __getitem__
selection = sel.select(self.shape, args, dataset=self)
File "/Users/yunjunz/tools/miniconda3/envs/insar/lib/python3.7/site-packages/h5py/_hl/selections.py", line 82, in select
return selector.make_selection(args)
File "h5py/_selector.pyx", line 272, in h5py._selector.Selector.make_selection
File "h5py/_selector.pyx", line 183, in h5py._selector.Selector.apply_args
TypeError: Indexing arrays must have integer dtypes```
Sorry about that. As a workaround, you can convert the 1D boolean array to an array of indices with .nonzero():
result = dset[(arr[:, 0] > 20).nonzero()[0]]
Thanks for the workaround solution @takluyver.
Most helpful comment
Sorry about that. As a workaround, you can convert the 1D boolean array to an array of indices with
.nonzero():