-
Notifications
You must be signed in to change notification settings - Fork 16
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
Exchange xr.Dataset.dims
by xr.Dataset.sizes
#159
Exchange xr.Dataset.dims
by xr.Dataset.sizes
#159
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Christopher,
thanks a lot for your PR. This is indeed a problem, which we should fix, however I'm not completely sure how one is supposed to do this nicely.
You suggested changes to a couple of ds.dims
calls, which are actually used as intended but still raise the warning. Currently, I see 4 possible remedies:
- We could either change these to
ds.sizes
calls which also works because it iterates over the keys. - We could add a
warnings.filterwarnings('ignore', module='xarray', category=FutureWarning, message="The return type of
Dataset.dims*")
to the__init__.py
. - We could add a context manager around the offending lines to suppress this specific warning.
- We could add a context manager inside of the user-facing API (i.e. inside the whole
.postprocess
and.destagger
methods). - We ignore the warnings by line number
warnings.simplefilter('ignore', lineno=<no>)
My opinions:
- It's fast and clean but I don't like it because it is the intended use of
ds.dims
- This works but it probably also changes the user's warnings environment.
- IMO this is a good solution from an engineering standpoint. It creates a lot of bloat-code though, which we will have to remove again.
- I'm not sure how smart that is. This makes huge changes in git-blame (because of the indenting) and does not suppress the warnings when testing individual functions.
- We will have to change the lineno every time we change something in the code but IMO this is the nicest solution, esp. because the code base does not change very quickly any more.
What do you think, @christopher-lw? And maybe @jthielen or @andersy005 know the best-practice solution for these kinds of issues?
Edit: I misunderstood the lineno
argument. This is the line of where the warning is raised (i.e. in the xarray/core.py file) and the the line where it is triggered (i.e. in our code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, sorry for my confusion.
Change Summary
To eliminate
FutureWarnings
by the call ofxr.Dataset.dims
inxwrf
it is replaced byxr.Dataset.sizes
according to the warning:Related issue number
No issue opened
Checklist
Please add any other relevant info below: