-
Notifications
You must be signed in to change notification settings - Fork 27
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
Fix DataView reading and writing #414
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ok, now I'm done for real. |
3f3da07
to
2e7ea70
Compare
- Dimension count check (on top of bounds checks) in DataView constructor: DataView dimensionality must match array dims exactly. - Simplify incoming slices using the 'slice.indices()' function: Converts potential negative or None 'start' or 'stop' to positive equivalents. - Pluralise '_slices' attribute to represent that it's a collection (tuple) of slice objects.
- Checks for single integer index and adds it to DataView 'start' (offset). - If it's a slice, simplifies using slice.indices() and transforms. - Performs out of bounds checks for the transformed slice or index.
- Use ._transform_coordinates() for _read_data() - Convert single slicing or single index to tuple when transforming
When the user supplies slices and indices that are fewer than the dimensionality of the DataView, a full-slice (slice(None)) is implied for the remaining dimensions.
When requested slice dimensions don't match DataArray dimensionality, raise IncompatibleDimensions error instead of IndexError. Added redundant test to DataView test file as well.
2e7ea70
to
8deb1fc
Compare
jgrewe
approved these changes
Oct 14, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the read and write methods for DataView and adds tests for all sorts of weird cases and fancy slicing.
The rules for slicing and slice combinations were made to match Python slicing behaviour, adapted for the case of the DataView. Most of the work is done in the
_transform_coordinates()
method. An important change from the previous way the indices were calculated is that now we rely onslice
objects and theslice.indices()
method to calculate the start and stop values for fancy slicing cases, like negative indexing and slicing beyond the end of an array, both of which are now closer to the way indexing works in Python and NumPy.New behaviour:
dataview[-N]
is legal only forN < len(dataview)
. The previous conversion simply calculatedlen(dataview) - N
and then passed the result to the underlying h5py function, which raised the error when necessary.stop
value of the DataView.