Skip to content
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

Add keep_variables keyword to open_dataset() #8450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

claytharrison
Copy link

@claytharrison claytharrison commented Nov 14, 2023

This is based on #895 by @tsupinie, following the suggestions on that PR made by @shoyer, but that was so old I decided it was best to do a completely new PR. XArray has changed quite a bit since then, so I had to make changes in several more files than the original PR did in order to get tests to pass.

I'm very new to working on XArray, and my approach here was to basically just mirror how the package handles drop_variables wherever that appears, with the necessary logical tweaks where appropriate. As such I've possibly touched something that shouldn't be (in particular I'm looking at xarray/backends/zarr.py and xarray/backends/common.py as places where I'm not quite sure if I've done things properly).

@max-sixty
Copy link
Collaborator

Thanks for the PR @claytharrison !

I don't know this code that well; it looks good from my perspective. Do others?

I'm guessing this is most useful if we have hundreds or thousands of variables and only want to load the metadata of a few? Since IME loading the metadata is v fast, and then we can drop the variables in xarray before loading their data?

@shoyer
Copy link
Member

shoyer commented Nov 17, 2023

I'm not sure we need this new API, or even that drop_variables would make sense if we were considering it today.

Why not open the dataset with decode_cf=False, drop any variables you don't need, and then decode with an explicit call to xarray.decode_cf?

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

Successfully merging this pull request may close these issues.

Opposite of drop_variables option in open_dataset()
3 participants