-
-
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
concat
and align
flips coordinates order
#9777
Comments
This is a similar, but fixed issue: #2811 |
I suspect the re-ordering happens in the example above because the "c" coordinate needs to be re-indexed while the other "date" and "d" coordinates do not need to be re-indexed. When all coordinate labels are the same in both I guess that for |
Thanks @benbovy for the details. |
@benbovy thanks for the great details! import pandas as pd
import xarray as xr
ds1 = pd.DataFrame({"date": [1, 1], "c": [1,2], "d": [3,4], "v":[5,6]}).set_index(['date', 'c', 'd']).to_xarray()
ds2 = pd.DataFrame({"date": [2, 2], "c": [1,3], "d": [3,4], "v":[5,6]}).set_index(['date', 'c', 'd']).to_xarray()
print(xr.concat([ds1, ds2],dim='date')) Gives:
While: import pandas as pd
import xarray as xr
ds1 = pd.DataFrame({"date": [1, 1], "c": [1,2], "d": [3,4], "v":[5,6]}).set_index(['date', 'c', 'd']).to_xarray()
ds2 = pd.DataFrame({"date": [2, 2], "c": [1,2], "d": [3,4], "v":[5,6]}).set_index(['date', 'c', 'd']).to_xarray()
print(xr.concat([ds1, ds2],dim='date')) Prints:
The |
What should be the natural order if we have ds1 and ds2 with concurring layouts? For your example there is a natural order which we might be able to keep track of (this can be fixed, imho). For contradicting layouts we almost everywhere resort to the layout of the first dataset. |
Good question.
|
What happened?
xr.concat()
andxr.align()
behavior is based on the values of coordinates, the result is surprisingWhat did you expect to happen?
Consistent behavior, stable coordinates.
Minimal Complete Verifiable Example
This gives the expected
(date, c, d)
:But changing one value of
c
results in(c,d,date)
coordinates.I tried to use
xr.align
instead, but that's similar.(date, c, d)
is coordinates are created:Changing a coordinate results in coordinate order
(c,d,date)
:MVCE confirmation
Relevant log output
No response
Anything else we need to know?
Maybe a good workaround or description in the docs is the solution if fixing this behavior is not straightforward.
Right now I have no idea how to append two disjoint Datasets along an axis.
transpose
changesDataArray
coordinates only.xr.merge()
works, but it's really slow (10x slower thanconcat
oralign
) for appending un-aligned datasets along an axis.Environment
The text was updated successfully, but these errors were encountered: