xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Add a `.drop_attrs` method

Open max-sixty opened this issue 2 years ago • 9 comments

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

max-sixty avatar Sep 30 '23 18:09 max-sixty

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.

headtr1ck avatar Sep 30 '23 19:09 headtr1ck

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")?

max-sixty avatar Sep 30 '23 21:09 max-sixty

But should probably have the same arguments and workings as drop_vars and 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...

max-sixty avatar Sep 30 '23 21:09 max-sixty

Hi team — what do we think about this? @pydata/xarray

max-sixty avatar Oct 07 '23 19:10 max-sixty

Thanks for the review @crusaderky .

I realize it's much easier to review when there are tests; I added those

max-sixty avatar Oct 08 '23 21:10 max-sixty

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!

shoyer avatar Oct 08 '23 21:10 shoyer

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?

max-sixty avatar Oct 08 '23 21:10 max-sixty

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?

max-sixty avatar Oct 17 '23 19:10 max-sixty

@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?

max-sixty avatar Feb 09 '24 18:02 max-sixty

Thanks for the ping @headtr1ck !

Any thoughts from others before we merge?

max-sixty avatar Jul 11 '24 17:07 max-sixty