-
-
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.testing.assert_equal does not test for dtype #4727
Comments
+1 on adding It could be default |
this has come up in #3706 (comment) before. |
My concern with If the default for Also, just checking dtype won't be sufficient in all cases. Consider this: import numpy as np
import xarray as xr
a = xr.DataArray(np.array(1.0, dtype=np.object))
b = xr.DataArray(np.array(1, dtype=np.object))
xr.testing.assert_identical(a, b) I think for the purpose of testing being able to make sure the result is exactly what you expect is important. |
There seems to be a subtle difference between comparing
xarray/xarray/core/dataarray.py Line 2792 in 03d8d56
while Lines 1457 to 1459 in 03d8d56
Thus once we compare import xarray as xr
air = xr.tutorial.open_dataset("air_temperature")
type(air._variables["lat"])
# xarray.core.variable.IndexVariable
type(air.air.coords["lat"])
# xarray.core.dataarray.DataArray edit: typo |
I agree with @toddrjen that the words of I would suggest we either:
Happy to help on this! |
In #4622 @toddrjen points out that
xr.testing.assert_equal
does not test for thedtype
, only for the value. Therefore the following does not raise an error:This comes back to numpy, i.e. the following is True:
Depending on the situation one or the other is desirable or not. Thus, I would suggest to add a
check_dtype
argument toxr.testing.assert_equal
and also toDataArray.equals
(andDataset
andVariable
andidentical
). I have not seen such an option in numpy, but pandas has it (e.g.pd.testing.assert_series_equal(left, right, check_dtype=True, ...)
. I would not change__eq__
.True
first and see how many failures this creates?pd.testing.assert_series_equal
has acheck_index_type
keyword. Probably we needcheck_coords_type
as well? This makes the whole thing much more complicated... Also Coordinate dtype changing to object after xr.concat #4543The text was updated successfully, but these errors were encountered: