when getting object by address do not fully instantiate when iterating#83
Conversation
|
thanks a lot @kmuehlbauer - mind fixing the test too, please, mate? @bnlawrence you got a minute have a look at Kai's proposed change pls? 🍺 |
|
@valeriupredoi I'm really sure there is a better solution to this here. I've only did this branch to let you know, what I'm about to. I've more details in #70 (comment). The main problem is, that pyfive raises |
I know @davidhassell was thinking about this too. Before I dive in, @davidhassell, did you think any more about it? (As it happens, I am dead sick of proposal spreadsheets, so thinking about this for an hour or two would be a blessed relief.) |
|
good man @kmuehlbauer - I usually open a Draft PR when it comes to these types, take your time, and am sure Bryan, David can help - this one's a bit out of my reach but I can help with fixing its tests etc, when time comes 🍺 |
|
@valeriupredoi Ah, sorry, this should have been a draft. |
Actually, it would be really useful to have a test (or tests) that shows the behaviour that is wanted here, which is presumably to fail when you want it to and not before. |
|
I would agree that Currently it's calling |
|
@bmaranville Thanks for chiming in. This seems like a good way forward. I'll try to implement your suggestions here the next day. But, if someone has free cycles, feel free to add or override here. |
|
How about we start from deciding that the |
| elif datatype_class == DATATYPE_ENUMERATED: | ||
| raise NotImplementedError( | ||
| "Enumerated datatype class not supported.") | ||
| return ("ENUMERATED", datatype_msg['size']) |
There was a problem hiding this comment.
@bnlawrence So, would this be something useful to return?
There was a problem hiding this comment.
Yes, I think so. The higher-level API for dtype will need to return uint8, but what we do in between is the key and I think we will need that information. We could check for that in the higher-level API, return uint8, and implement check_enum_dtype to look for this. We could quite quickly then at least implement the ability to look at the enumeration integers, even if we can't immediately decode the dictionary stored in the Enumeration Property Description.
There was a problem hiding this comment.
I think DATATYPE_ENUMERATED can have a number of base types (any of the integer types?), not just uint8 - the base type is specified in the datatype message.
There was a problem hiding this comment.
Quite right. Thanks for the reminder.
|
I have added a new branch (enum_and_friends) where we can work on enum support. For the moment it is very dysfunctional, but it's a framework to work from, and includes a test which should make sure we support the h5py interface. Unfortunately I need to put this down to work on some other things and will be unlikely to follow all the way through before early September - but you never know, depends on progress and boredom levels with the other stuff I have to do right now. Ideally this branch also sorts out the visititems issue properly, but it might be that proceeding with this hack for the h5netcdf application is the right temporary expedient - but someone else will need to write the test for that. |
(And yes, I should have done it with a fork and a draft pull request, sorry, but I'm time poor right now and that would have taken me a wee bit longer to set up in VSC.) |
| queue = deque([(self.name.rstrip('/'), self)]) | ||
| while queue: | ||
| base, grp = queue.popleft() | ||
| for name, link_addr in grp._links.items(): | ||
| full_path = f"{base}/{name}" if base else f"/{name}" | ||
| # check address without instantiating | ||
| if link_addr == obj_addr: | ||
| # return instantiated object | ||
| return grp[name] | ||
| # descend only if it's a subgroup (need to instantiate minimally) | ||
| # would be neat to have .is_group | ||
| dataobjs = DataObjects(self.file._fh, link_addr) | ||
| if not dataobjs.is_dataset and not dataobjs.is_datatype: | ||
| queue.append((full_path, grp[name])) |
There was a problem hiding this comment.
This gets the object by address without instantiating completely. The DataObject creation is needed, to check for group and step into groups. Not sure if this more performant, but it doesn't instantiate the complete Datasets.
This reverts commit d37c080.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #83 +/- ##
==========================================
+ Coverage 71.93% 72.06% +0.12%
==========================================
Files 11 11
Lines 2423 2434 +11
Branches 364 368 +4
==========================================
+ Hits 1743 1754 +11
+ Misses 583 582 -1
- Partials 97 98 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
OK, great, this seems to work now. I'll have to add tests. |
|
JFTR, as enum type is now handled in another PR, I'm concentrating here in the dereferencing of REFERENCE. This was done by using visititems which instantiated all objects which have been iterated over. This now just compares the addresses and do a minimal test for group, where I added a respective |
|
Ready for review from my side. Thanks for all the suggestions and details. |
|
I was able to gain full coverage by adding another test. I'll leave this be now, so reviewers can have a look. |
|
Thanks, @kmuehlbauer - I'm paying attention again now :), and will have a look at this PR today ... |
davidhassell
left a comment
There was a problem hiding this comment.
Hi @kmuehlbauer,
Thank you for this change. The tests uses cases look good, the tests pass for me too. The new code makes sense, and I always like a corrected spelling mistake :).
We'll get this merged and out in a new PyPi release (0.5.1) today or tomorrow, so that it can be immediately used in the h5netcdf pyfive backend PR (h5netcdf/h5netcdf#273).
Cheers,
David
|
Great news @davidhassell, happy to contribute. |
|
(I'll be including this in the new Change Log that I'm about to start ...) |
|
indeed, great many thanks @kmuehlbauer and @davidhassell 🍺 x2 |
Description
The changes in this PR prevents instantiating objects fully when retrieving objects by address (eg. when dereferencing). This was reported in #70 (comment).
Checklist