Open JGuetschow opened 3 weeks ago
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!
This does seem like confusing behavior. We'd def welcome a fix.
So far I just have a workaround for our use case which merged the additional coordinates independently (treat them like variables). I looked into the xarray code, but without sufficient time to understand it, I think chances are high that I break more than I fix. I probably won't have time to dig deeper before November, but if it's still open then I'll take a look.
An easy workaround is actually to use merge
were possible as I could not reproduce the problem with merge (but I only tested the use cases in our code, so I might have missed something)
What happened?
fillna
(and other functions which need aligning) remove non-indexed extra coordinates (along a dimensions which also have an indexed coordinates)Below I have an example with
fillna
, But I have experienced similar things withcombine_first
and assume it will happen whenever alignment is needed. More on what I think is happening below.What did you expect to happen?
I expected the extra coordinate to remain in place as it was defined consistently in both datasets. Alternatively an error message would also help to understand what's going on. Currently it's dropped silently.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
The problem only occurs when the
.loc
is done on the dimension with the additional coordinate. I think the reason for the problem is the following:align
fills the additional coordinate from the smaller dataset (same for dataarray) withnp.nan
to expand it to the larger dataset. Later in the process the aligned coordinates are passed tomerge_coordinates_without_align
which removes the additional coordinate as it containsnp.nan
in one of the datasets where the other dataset has values.So the non-index coordinates are neither combined like the indexed coordinates, nor filled like the data variables.
Below a short example involving only
align
andmerge_coordinates_without_align
.Environment