Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Numpy newaxis slicing support #2409

Open
desplenterkarel opened this issue Apr 15, 2024 · 2 comments
Open

No Numpy newaxis slicing support #2409

desplenterkarel opened this issue Apr 15, 2024 · 2 comments

Comments

@desplenterkarel
Copy link

Description:

H5py currently doesn't support adding np.newaxis when slicing a data array.

with h5py.File(file, 'r') as F:
        return F[array_group][:,np.newaxis,:,:]

as following return is given:

' File "", line 77, in read_hdf_frame_v1
return F[array_group][:,np.newaxis,:,:]
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 "
\lib\site-packages\h5py_hl\dataset.py", line 831, in getitem
selection = sel.select(self.shape, args, dataset=self)
File "****lib\site-packages\h5py_hl\selections.py", line 82, in select
return selector.make_selection(args)
File "h5py_selector.pyx", line 282, in h5py._selector.Selector.make_selection
File "h5py_selector.pyx", line 181, in h5py._selector.Selector.apply_args
TypeError: Selection can't process None'

'Summary of the h5py configuration

h5py 3.10.0
HDF5 1.14.2
Python 3.10.13 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:24:38) [MSC v.1916 64 bit (AMD64)]
sys.platform win32
sys.maxsize 9223372036854775807
numpy 1.26.4
cython (built with) 0.29.36
numpy (built against) 1.21.6
HDF5 (built against) 1.14.2'

@tacaswell
Copy link
Member

I am not sure that this is something we want to support as it is doing an implicit reshape as part of the read. I would expect:

    return F[array_group][:][:,np.newaxis,:,:]

would would and I think is clearer ("Please read the whole data set" and then "please resahpe it by sticking an extra axis in").

@aragilar
Copy link
Member

I agree. I wonder if we should check for None earlier (e.g. in __getitem__) and raise a more helpful error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants