xarray
xarray copied to clipboard
Add a `.drop_attrs` method
Part of #3891
~Do we think this is a good idea? I'll add docs & tests if so...~
Ready to go, just needs agreement on whether it's good
I think it's a good idea.
But should probably have the same arguments and workings as drop_vars and others.
If you want to control the behavior of dropping attrs from variables or only dataset level attrs is another question.
If you want to control the behavior of dropping attrs from variables or only dataset level attrs is another question.
+1
What are variable-level attrs generally used for? For semantic information ("collected on 2023-09-30") or encoding-like information ("encoded as unicode")?
But should probably have the same arguments and workings as
drop_varsand others.
Yes, I was thinking about it a bit more like .reset_encoding — #8259. We could definitely allow passing attrs to drop. I'm not sure what we should do with the errors term, given attrs can be in multiple places...
Hi team — what do we think about this? @pydata/xarray
Thanks for the review @crusaderky .
I realize it's much easier to review when there are tests; I added those
My main concern is the meaning of "drop attrs" could be confusing:
- does it refer to dropping specific attrs (like the other drop methods) or all attrs? Potentially this could be controlled by an optional argument. I don't think
ds.drop_attrs()would be confusing. - does it refer to attrs on the top level object or also attrs on coordinates/data variables? The former is what I would expect but some users might want the later, too.
Overall I think this is probably a good idea, though. Certainly I have written this sort of thing many times!
My main concern is the meaning of "drop attrs" could be confusing:
I'm very open-minded here! My main motivation is to put less weight on keep_attrs parameter throughout the API.
What's a good way of deciding? We could do what keep_attrs does? Or add a deep param?
I've now added a deep kwarg, which controls whether it clears the attrs of all variables.
I've provisionally set it as deep=True. This is more aggressive than keep_attrs. What do we think?
@pydata/xarray I realize this is still hanging!
What's the best way of resolving? My guess is that there's consensus that the method would be useful, but maybe not on how "deep" it should go. Should we pick something and merge?
Thanks for the ping @headtr1ck !
Any thoughts from others before we merge?