Skip to content

Update ahead of change of 'item in ds' behavior in xarray v0.11 #251

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
wants to merge 1 commit into from

Conversation

spencerahill
Copy link
Owner

Just updated to xarray v0.10 and started getting a lot of deprecation warnings when running aospy due to pydata/xarray#1645, c.f. pydata/xarray#1267. So I tried to find it everywhere this comes up and fix it.

@spencerkclark let me know if you see any reason why we shouldn't do this, or if I missed anything.

Copy link
Collaborator

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spencerahill thanks for making these updates. It's clear we will need to be careful about this update to xarray.

In these places it seems we were relying on __contains__ working differently for DataArrays and Datasets.

  • For DataArrays we were checking if a name was a key in the dictionary of coordinates.
  • For Datasets we were checking if a name was a key in either the dictionary of coordinates or data variables.

Do you know where exactly the warnings were emanating from? The warnings should only stem from when we use the __contains__ operator on a DataArray. If some of these methods are called using Datasets we probably want to check if the name is in the data variables dictionary as well (and therefore should use the original VAR_STR in ds logic).

My initial thought was that since _prep_time_data is called before _sel_var in data_loader.load_variable:

aospy/aospy/data_loader.py

Lines 278 to 280 in 389961a

ds, min_year, max_year = _prep_time_data(ds)
ds = set_grid_attrs_as_coords(ds)
da = _sel_var(ds, var, self.upcast_float32)

ds must always be a Dataset, but it seems if this warning was triggered, it must sometimes be a DataArray. Did you encounter these warnings when doing calculations using aospy or when running the test suite?

@spencerahill
Copy link
Owner Author

Oy, this is an embarrassing one. I forgot that I was running on an old branch for one of my research projects. I just ran the example main script and the test suite on develop and no warnings are emitted.

Thanks @spencerkclark for responding, sorry for wasting your time!

@spencerahill spencerahill deleted the xarray-v0.10-warnings branch March 23, 2018 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants