-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow setting (or skipping) new indexes in open_dataset #8051
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
Merged
+185
−10
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c703ebc
add set_indexes parameter to open_dataset
benbovy 6f54cd5
implement set_indexes in (zarr) backend store
benbovy f77aac7
Merge branch 'main' into backend-set-indexes
dcherian eae983b
Merge branch 'main' into backend-set-indexes
TomNicholas dfe6496
Merge branch 'main' into backend-set-indexes
keewis 145ae1c
replace `set_indexes` with `create_default_indexes`
keewis 192c367
make sure indexes set by the backend survive
keewis f5823a7
also add the parameter to `open_datatree`
keewis 2ff8402
share the implementation of the default indexes creation
keewis 82d629b
Merge branch 'main' into backend-set-indexes
keewis de5ce26
Merge branch 'main' into backend-set-indexes
keewis 294b2f7
check that the store backend entrypoint does not create default indexes
keewis 5c3a843
actually do not create default indexes in the backends
keewis 08939de
rename the helper
keewis 0f281b1
Merge branch 'main' into backend-set-indexes
dcherian 4620490
Merge branch 'main' into backend-set-indexes
dcherian 95dbf8e
move the handling of `create_default_indexes` up the call stack
keewis eb4f866
Merge branch 'main' into backend-set-indexes
keewis d7e6daa
what's new
keewis 687f0c2
Merge branch 'main' into backend-set-indexes
benbovy 3d483d3
Fix
dcherian 741564e
fix again
dcherian 8889eda
also create default indexes without chunks
keewis 804db4c
also copy `_close`
keewis 75c1dd6
reuse the code for copying `_close`
keewis a0d94fb
refactor
dcherian bbc263b
Merge branch 'main' into backend-set-indexes
dcherian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
AbstractDataStore, | ||
BackendEntrypoint, | ||
) | ||
from xarray.core.coordinates import Coordinates | ||
from xarray.core.dataset import Dataset | ||
|
||
if TYPE_CHECKING: | ||
|
@@ -36,6 +37,7 @@ def open_dataset( | |
concat_characters=True, | ||
decode_coords=True, | ||
drop_variables: str | Iterable[str] | None = None, | ||
set_indexes: bool = True, | ||
use_cftime=None, | ||
decode_timedelta=None, | ||
) -> Dataset: | ||
|
@@ -56,8 +58,19 @@ def open_dataset( | |
decode_timedelta=decode_timedelta, | ||
) | ||
|
||
ds = Dataset(vars, attrs=attrs) | ||
ds = ds.set_coords(coord_names.intersection(vars)) | ||
# split data and coordinate variables (promote dimension coordinates) | ||
data_vars = {} | ||
coord_vars = {} | ||
for name, var in vars.items(): | ||
if name in coord_names or var.dims == (name,): | ||
coord_vars[name] = var | ||
else: | ||
data_vars[name] = var | ||
|
||
# explicit Coordinates object with no index passed | ||
coords = Coordinates(coord_vars, indexes={}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine given our rules for propagating coordinate variables when extracting DataArrays but it is potentially confusing with |
||
|
||
ds = Dataset(data_vars, coords=coords, attrs=attrs) | ||
ds.set_close(filename_or_obj.close) | ||
ds.encoding = encoding | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.