-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
xr.concat concatenates along dimensions that it wasn't asked to #8231
Comments
A consequence of the alignment behavior described in #6806 |
The PR suggests using the proposed
ds1 = xr.Dataset(
coords={
'x_center': ('x_center', [1, 2, 3]),
'x_outer': ('x_outer', [0.5, 1.5, 2.5, 3.5]),
},
)
ds1 = xr.Dataset(
data_vars={
'a': ('x_center', [1, 2, 3]),
'b': ('x_outer', [0.5, 1.5, 2.5, 3.5]),
},
) This tests just enforce that the expected behavior happens. |
Wouldn't |
Indeed join='exact' raises an error: import xarray as xr
ds1 = xr.Dataset(
coords={
'x_center': ('x_center', [1, 2, 3]),
'x_outer': ('x_outer', [0.5, 1.5, 2.5, 3.5]),
},
)
ds2 = xr.Dataset(
coords={
'x_center': ('x_center', [4, 5, 6]),
'x_outer': ('x_outer', [4.5, 5.5, 6.5]),
},
) xr.concat([ds1, ds2], dim='x_center', join='exact')
|
What happened?
Here are two toy datasets designed to represent sections of a dataset that has variables living on a staggered grid. This type of dataset is common in fluid modelling (it's why xGCM exists).
Calling
xr.concat
on these withdim='x_center'
happily concatenates thembut notice that the returned result has been concatenated along both
x_center
andx_outer
.What did you expect to happen?
I did not expect this to work. I definitely didn't expect the datasets to be concatenated along a dimension I didn't ask them to be concatenated along (i.e.
x_outer
).What I expected to happen was that (as by default
coords='different'
) both variables would be attempted to be concatenated along thex_center
dimension, which would have succeeded for thex_center
variable but failed for thex_outer
variable. Indeed, if I name the variables differently so that they are no longer coordinate variables then that is what happens:Minimal Complete Verifiable Example
No response
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
I was trying to create an example for which you would need the automatic combined concat/merge that happens within
xr.combine_by_coords
.Environment
xarray
2023.8.0
The text was updated successfully, but these errors were encountered: