Initial version of null dataspace code #664

Merged
merged 3 commits into from Mar 9, 2016

Projects

None yet

2 participants

@aragilar
Contributor
aragilar commented Jan 5, 2016

Closes #279.

@andrewcollette andrewcollette commented on an outdated diff Jan 6, 2016
h5py/_hl/base.py
+ This can have an associated dtype, but has no shape or data. This is not
+ the same as an array with shape (0,).
+ """
+ shape = None
+
+ def __init__(self, dtype):
+ self.dtype = dtype
+
+ def __eq__(self, other):
+ if isinstance(other, Empty) and self.dtype == other.dtype:
+ return True
+ return False
+
+ def __repr__(self):
+ return "Empty(dtype={})".format(repr(self.dtype))
@andrewcollette
andrewcollette Jan 6, 2016 Member

I think {r} can be used for this.

@andrewcollette
Member

A couple of things come to mind:

  1. #279 suggests that accessing the contents of an empty dataset would produce an Empty object... this PR simply raises an exception. Thoughts?
  2. What does Dataset.shape report for empty datasets (ideally it should be None)?
  3. There will need to be a section added to the documentation describing how Empty works
  4. How can I create empty datasets and attributes using Empty? #279 suggests this should be handled by assigning to a name in the file (or a new entry in .atts), or by using shape=None when calling create_dataset.
@aragilar
Contributor

Updated the code (I thought I'd written both the read and write parts, but was evidently imaging things...).

The code should act as expected, but I do have one question: should h5py.Empty have a default? It'd be easier to use. On the other hand if the default ever changes, it'd be less obvious than if the default dtype for create_dataset changed.

@aragilar
Contributor
aragilar commented Mar 2, 2016

@andrewcollette Is there anything that's still missing?

@andrewcollette andrewcollette commented on an outdated diff Mar 5, 2016
h5py/_hl/dataset.py
@@ -399,6 +405,10 @@ def __getitem__(self, args):
* Boolean "mask" array indexing
"""
args = args if isinstance(args, tuple) else (args,)
+ if is_empty_dataspace(self.id):
+ if args != tuple():
@andrewcollette
andrewcollette Mar 5, 2016 Member

I think we should also accept Ellipsis. For example, scalar datasets can't be sliced with dset[:] but can with dset[...].

@andrewcollette
Member

@aragilar, thanks for pinging me on this; it had slipped off my radar. This will be an excellent feature! Just add the ability to index with Ellipsis and I'll merge it.

@aragilar
Contributor
aragilar commented Mar 8, 2016
@andrewcollette andrewcollette merged commit fc58fc6 into h5py:master Mar 9, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@aragilar aragilar deleted the aragilar:empty_datasets branch Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment