-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix open_mfdataset()
dropping time encoding attrs
#309
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef9c1dd
Fix `open_mfdataset()` dropping time encoding attrs
tomvothecoder 11fa200
Update test
tomvothecoder c8292b5
Fix test
tomvothecoder 51db486
Fix test to avoid breaking between xarray versions
tomvothecoder 51815e7
Move `time_encoding` logic to `open_mfdataset()`
tomvothecoder 86760e7
Use original_shape of final ds and fix test
tomvothecoder 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 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 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 |
---|---|---|
|
@@ -232,6 +232,8 @@ def open_mfdataset( | |
if time_encoding is not None: | ||
time_dim = get_axis_dim(ds, "T") | ||
ds[time_dim].encoding = time_encoding | ||
# Update "original_shape" to reflect the final time coordinates shape. | ||
ds[time_dim].encoding["original_shape"] = ds[time_dim].shape | ||
Comment on lines
+235
to
+236
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. Use the "original_shape" of the final merged time coordinates. |
||
|
||
return ds | ||
|
||
|
@@ -448,9 +450,11 @@ def _keep_time_encoding(paths: Paths) -> Dict[Hashable, Any]: | |
# FIXME: Remove `type: ignore` comment after properly handling the type | ||
# annotations in `_get_first_path()`. | ||
ds = open_dataset(first_path, decode_times=True, add_bounds=False) # type: ignore | ||
|
||
time_coord = get_axis_coord(ds, "T") | ||
|
||
time_encoding = time_coord.encoding | ||
time_encoding["source"] = paths | ||
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. Set "source" to the |
||
|
||
return time_coord.encoding | ||
|
||
|
||
|
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.
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.
My theory about xarray generated datasets keeping time encoding attributes was wrong. Xarray drops time encoding attributes if coordinates need to merged. If datasets share the same coordinates, no merging needs to be performed so the time encoding attributes are maintained, which was happening in the old version of this test.
I fixed this test by attempting to open two datasets, with the second being an extension of the first by 1 time coordinate.