-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add defaults during concat 508 #3545
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
Changes from 2 commits
baeebed
a96583b
af347e7
418c538
9e35c84
f7124a3
47f7e4d
df3693e
c21dcd4
4e01bd9
515b9c1
cf5b8bd
3bf3931
03f9b3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import pandas as pd | ||
| import numpy as np | ||
|
|
||
| from . import dtypes, utils | ||
| from .alignment import align | ||
| from .common import full_like | ||
| from .duck_array_ops import lazy_array_equiv | ||
| from .merge import _VALID_COMPAT, unique_variable | ||
| from .variable import IndexVariable, Variable, as_variable | ||
|
|
@@ -370,10 +372,22 @@ def ensure_common_dims(vars): | |
| # n.b. this loop preserves variable order, needed for groupby. | ||
| for k in datasets[0].variables: | ||
| if k in concat_over: | ||
| try: | ||
| vars = ensure_common_dims([ds.variables[k] for ds in datasets]) | ||
| except KeyError: | ||
| raise ValueError("%r is not present in all datasets." % k) | ||
| variables = [] | ||
| for ds in datasets: | ||
| # if one of the variables doesn't exist find one which does | ||
| # and use it to create a fill value | ||
| if k not in ds.variables: | ||
| for ds in datasets: | ||
|
||
| if k in ds.variables: | ||
| # found one to use as a fill value, fill with np.nan | ||
dcherian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| filled = full_like( | ||
| ds.variables[k], fill_value=np.nan, dtype=np.double | ||
| ) | ||
| break | ||
| variables.append(filled) | ||
| else: | ||
| variables.append(ds.variables[k]) | ||
| vars = ensure_common_dims(variables) | ||
| combined = concat_vars(vars, dim, positions) | ||
| assert isinstance(combined, Variable) | ||
| result_vars[k] = combined | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.