Skip to content

warn at import time if xr.core.options.OPTIONS["keep_attrs"] is False #77

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

Closed
dcherian opened this issue Aug 18, 2020 · 6 comments
Closed
Labels
good first issue Good for newcomers

Comments

@dcherian
Copy link
Contributor

Maybe say something like

"cf_xarray works best when xarray keeps attributes by default. Please run xr.set_options(keep_attrs=True)"

This may be annoying though. We should definitely mention this in the docs (#73)

@jthielen
Copy link
Contributor

I think it would be good to include the warning, but perhaps give the option to disable it with a cf-xarray option or environment variable if the user wants keep_attrs to be False.

@dcherian
Copy link
Contributor Author

but you can't set a cf_xarray option without importing it first which would show a warning ;)

to be clear, this warning will only be shown once at import time not on every operation.

@jthielen
Copy link
Contributor

but you can't set a cf_xarray option without importing it first which would show a warning ;)

to be clear, this warning will only be shown once at import time not on every operation.

Ah, so an environment variable it would have to be!

@dcherian
Copy link
Contributor Author

turns out the default is "default" so we could also only raise the warning is OPTIONS["keep_attrs"] == "default". So we wouldn't bug anyone who has explicitly opted out of keep_attrs

@jthielen
Copy link
Contributor

turns out the default is "default" so we could also only raise the warning is OPTIONS["keep_attrs"] == "default". So we wouldn't bug anyone who has explicitly opted out of keep_attrs

Even better!

@dcherian dcherian added the good first issue Good for newcomers label Sep 19, 2020
@dcherian
Copy link
Contributor Author

One (minor) issue with implementing this is that linters will format code to something like

import cf_xarray  # will raise warning here.
import xarray

xr.set_options(keep_attrs=True)

making the warning useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants