-
-
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
32- vs 64-bit coordinates coordinates in where() #6573
Comments
This does seem very odd. Does anyone have any ideas? As per @forman , changing -c32 = xr.DataArray(np.linspace(0, 1, 10, dtype=np.float32), dims='x')
+c32 = xr.DataArray(np.linspace(0, 1, 10, dtype=np.float64), dims='x') ...causes the assertion to pass. I'm not sure using floats as indexes is great, but I wouldn't have expected the results to be like this... |
Yes that's right: v32.indexes["x"].intersection(v64.indexes["x"])
# Float64Index([0.0, 1.0], dtype='float64', name='x') I think the issue is more general than xr.align(c32, c64)
# (<xarray.DataArray (x: 10)>
# array([0. , 0.11111111, 0.22222222, 0.33333334, 0.44444445,
# 0.5555556 , 0.6666667 , 0.7777778 , 0.8888889 , 1. ],
# dtype=float32)
# Dimensions without coordinates: x,
# <xarray.DataArray (x: 10)>
# array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
# 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])
# Dimensions without coordinates: x)
xr.align(v32.x, v64.x)
# (<xarray.DataArray 'x' (x: 2)>
# array([0., 1.], dtype=float32)
# Coordinates:
# * x (x) float64 0.0 1.0,
# <xarray.DataArray 'x' (x: 2)>
# array([0., 1.])
# Coordinates:
# * x (x) float64 0.0 1.0) A possible solution would be to handle this special case internally by converting one of the index according to the dtype of the coordinate labels of the other index, similarly to what we are currently doing for the labels that are passed to However, I'm also wondering whether or not we should consider this as a bug. It would make sense to have a behavior that is consistent with v32.x.equals(v64.x)
# False -- Should we return True here? This would be quite weird and wouldn't match the Xarray, Pandas and Numpy behavior below: v32.indexes["x"].equals(v64.indexes["x"])
# False
c64.equals(c32)
# False
np.all(c32.values == c64.values)
# False |
It could be coherent to have:
I could also imagine raising an error here and having the user coerce the type. That seems less surprising that the current situation. Other languages don't allow floats to be compared for equality at all... |
Maybe we should add an explicit |
I like that. |
I also like the idea of alignment with some tolerance. There is an open PR #4489, which needs to be reworked in the context of the explicit index refactor. Alternatively to a new kwarg we could add an index build option, e.g., |
What happened?
I'm struggling whether this is a bug or not. At least I faced a very unexpected behaviour.
For two given data arrays
a
andb
with same dimensions and equal coordinates,c
forc = a.where(b)
should have equal dimensions and coordinates.However if the coordinates of
a
have dtype of float32 and those ofb
are float64, then the dimension sizes ofc
will always be two. Of course, this way the coordinates ofa
andb
are no longer exactly equal, but from a user perspective they represent the same labels.The behaviour is likely caused by the fact that the indexes generated for the coordinates are no longer strictly equal, therefore
where()
picks only the two outer cells of each dimension. Allowing to explicitly pass indexes may help here, see #6392.What did you expect to happen?
In the case described above, the dimensions and coordinates of
c
should be equal toa
(andb
).Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
The text was updated successfully, but these errors were encountered: