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

Type error in h5py when data_array index exceeds number of items in data_array #299

Closed
thladnik opened this issue May 23, 2018 · 1 comment
Assignees

Comments

@thladnik
Copy link

traceData = self.bHandle.data_arrays[traceName][int(traceStart*Fs):int(traceEnd*Fs)]
  File "/usr/local/lib/python3.5/dist-packages/nixio/data_array.py", line 137, in __getitem__
    self._read_data(raw, count, offset)
  File "/usr/local/lib/python3.5/dist-packages/nixio/pycore/data_array.py", line 82, in _read_data
    super(DataArray, self)._read_data(data, count, offset)
  File "/usr/local/lib/python3.5/dist-packages/nixio/pycore/data_array.py", line 28, in _read_data
    dataset.read_data(data, count, offset)
  File "/usr/local/lib/python3.5/dist-packages/nixio/pycore/h5dataset.py", line 57, in read_data
    self.dataset.read_direct(data, sl)
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/dataset.py", line 656, in read_direct
    for mspace in dest_sel.broadcast(source_sel.mshape):
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/selections.py", line 299, in broadcast
    raise TypeError("Can't broadcast %s -> %s" % (target_shape, count))
TypeError: Can't broadcast (97080,) -> (97081,)

Nixpy does not throw an exception when the index in a data_array call exceeds the number of items in the data_array. Instead it causes an error in h5py when the number of items retrieved from file does not match the number of expected items.
Maybe nixpy could instead check if the index is out of range before calling h5py.

@achilleas-k
Copy link
Member

Good idea. A nicer error from nixpy would be more informative. Thanks for the suggestion.

@achilleas-k achilleas-k self-assigned this May 23, 2018
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jul 11, 2018
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jul 12, 2018
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jul 12, 2018
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jul 12, 2018
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jul 12, 2018
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
achilleas-k added a commit to achilleas-k/nixpy that referenced this issue Jan 18, 2019
H5Py throws ValueError for out-of-bounds indexing. We catch it and throw
IndexError instead, reusing the error message from H5Py.

This also makes indexing more flexible. Slices now work the same as in
numpy, so no slice is ever out-of-bounds. The corresponding test has
been updated accordingly.

This is an updated version of PR G-Node#303, which was a fix for G-Node#299.
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

2 participants