-
Notifications
You must be signed in to change notification settings - Fork 3
Direct-access attributes #134
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
Conversation
I mean, you're in charge here, could you not provide dict-like behaviour AND the conveniences such as The only reason I can see for not doing this1 would be the Principle of Least Astonishment, if there are opportunities for confusion if we give the user something that quacks like a dictionary but is in fact something else. Footnotes
|
Yes, on reflection maybe I'm still missing a trick or two here. Already, the NcData/NcVariable init methods are flexible in what you can pass to the 'attributes' : they detect whether you are passing dicts or lists of NcAttribute, or dicts of values + act appropriately. So we can be equally flexible here. |
Update 2025-07-31Now getting the house in order with completion of #118 and #116 Looking again at this, and recent traffic indicating there at least some users who may have an 'interest' in existing behaviour, A less disruptive approach would be to avoid the rename of the existing Perhaps instead, we should leave Also, on review, I am still a bit surprised about some of the existing behaviour, as even simple numeric values are returned as numpy array-scalars rather than 'pure' Python objects : So in that respect, |
Again, you're in charge, so I'm not wedded to what I'm saying. But I would argue that now is the time for breaking changes. Granted this might hurt some early users, but how many future users are going to get burned if the existing |
There's never one simple answer to this question ! Ping @valeriupredoi @schlunma : you've shown the most active external-contributor interest here so far. |
|
There are not too many uses of ncdata in our code base right now, and as far as I can tell we are not using However, to be extra safe, it would be helpful if you release a new version with the breaking changes before the end of August before our next release, so we could fix any problems before that. This will be our first release that includes ncdata, so past releases would not be affected. |
Thanks, that's really useful ! |
|
OK I've had a slight change of heart on this now, which actually makes things simpler. In short, the proposal here now has a So, I came to the conclusion that
But I do expect that users will use attrvals in preference most of the time, and will be advising that. From the effects seen in changed files, I think it's clear that the new mechanism does make a lot of operations look neater and more natural. Not least, a whole lot of sources no longer have to import 'NcAttribute'. |
|
TODO
|
f630e11 to
2fca4b2
Compare
|
Nearly there! Still to do
|
Closes #117
Provide a simple name: value access to attributes.
The original NameMap of {name: NcAttribute} is still present as data._attributes, and still dominates the behaviour.
Initial Status 2025-06-13
The tests are now all passing, but the docs are now a mess and a lot needs reconsidering.
Much has got a lot simpler, but there are downsides :
.. incidentally, I think we are missing some testing for different forms of attributes arg in NcData/NcVariable creation ??