Skip to content
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

Two strange errors in tests TestVariable using .copy() #3778

Closed
ArchangeGabriel opened this issue Feb 18, 2020 · 7 comments · Fixed by #3788
Closed

Two strange errors in tests TestVariable using .copy() #3778

ArchangeGabriel opened this issue Feb 18, 2020 · 7 comments · Fixed by #3788

Comments

@ArchangeGabriel
Copy link
Contributor

Setup is as described in #3777.

The two failures are the following ones:

____________________ TestVariable.test_index_0d_not_a_time _____________________

self = <xarray.tests.test_units.TestVariable object at 0x7f3926b2ad00>

    def test_index_0d_not_a_time(self):
        d = np.datetime64("NaT", "ns")
        x = self.cls(["x"], [d])
>       self._assertIndexedLikeNDArray(x, d)

xarray/tests/test_variable.py:206: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <xarray.tests.test_units.TestVariable object at 0x7f3926b2ad00>
variable = <xarray.Variable (x: 1)>
<Quantity(['NaT'], 'meter')>
expected_value0 = numpy.datetime64('NaT'), expected_dtype = None

    def _assertIndexedLikeNDArray(self, variable, expected_value0, expected_dtype=None):
        """Given a 1-dimensional variable, verify that the variable is indexed
        like a numpy.ndarray.
        """
        assert variable[0].shape == ()
        assert variable[0].ndim == 0
        assert variable[0].size == 1
        # test identity
>       assert variable.equals(variable.copy())
E       AssertionError: assert False
E        +  where False = <bound method Variable.equals of <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>>(<xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>)
E        +    where <bound method Variable.equals of <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>> = <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>.equals
E        +    and   <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')> = <bound method Variable.copy of <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>>()
E        +      where <bound method Variable.copy of <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>> = <xarray.Variable (x: 1)>\n<Quantity(['NaT'], 'meter')>.copy

xarray/tests/test_variable.py:151: AssertionError
_____________________ TestVariable.test_equals_all_dtypes ______________________

self = <xarray.tests.test_units.TestVariable object at 0x7f39282b4e50>

    def test_equals_all_dtypes(self):
        for v, _ in self.example_1d_objects():
            v2 = v.copy()
>           assert v.equals(v2)
E           AssertionError: assert False
E            +  where False = <bound method Variable.equals of <xarray.Variable (x: 3)>\n<Quantity(['2000-01-01T00:00:00.000000000' '2000-01-02T00:00:00.000000000'\n '2000-01-03T00:00:00.000000000'], 'meter')>>(<xarray.Variable (x: 3)>\n<Quantity(['2000-01-01T00:00:00.000000000' '2000-01-02T00:00:00.000000000'\n '2000-01-03T00:00:00.000000000'], 'meter')>)
E            +    where <bound method Variable.equals of <xarray.Variable (x: 3)>\n<Quantity(['2000-01-01T00:00:00.000000000' '2000-01-02T00:00:00.000000000'\n '2000-01-03T00:00:00.000000000'], 'meter')>> = <xarray.Variable (x: 3)>\n<Quantity(['2000-01-01T00:00:00.000000000' '2000-01-02T00:00:00.000000000'\n '2000-01-03T00:00:00.000000000'], 'meter')>.equals

xarray/tests/test_variable.py:386: AssertionError

I have no idea what’s wrong here.

@mathause
Copy link
Collaborator

Could you list the versions of the installed packages, i.e. the output of xr. show_versions()

@ArchangeGabriel
Copy link
Contributor Author

Sure:

INSTALLED VERSIONS
------------------
commit: None
python: 3.8.1 (default, Jan 22 2020, 06:38:00) 
[GCC 9.2.0]
python-bits: 64
OS: Linux
OS-release: 5.5.3-arch1-1
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.3

xarray: 0.15.0
pandas: 1.0.1
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.1.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.1
dask: None
distributed: None
matplotlib: 3.1.3
cartopy: None
seaborn: 0.10.0
numbagg: None
setuptools: 45.2.0
pip: None
conda: None
pytest: 5.3.5
IPython: None
sphinx: None

BTW, why does it report h5py? I did not see it in the list of optional dependencies. Same for distributed by the way.

@mathause
Copy link
Collaborator

@keewis could it be that the wrong version of pint is installed? Should pint be added to xr.show_versions?

@ArchangeGabriel
Copy link
Contributor Author

I have pint 0.10.1, and 0.10 definitively changed a lot of things as also shown in #3266 (comment).

@max-sixty
Copy link
Collaborator

max-sixty commented Feb 19, 2020

Should pint be added to xr.show_versions?

👍

@keewis
Copy link
Collaborator

keewis commented Feb 19, 2020

since pint became (or will become, once #3594 is closed) a optional dependency, we will definitely have to add it to show_versions.

Note that none of them will fail with dask installed (which is why we didn't catch this with CI):
without dask:

d = np.datetime64("NaT", "ns")
v = xr.Variable(["x"], ureg.Quantity([d], ureg.m))
assert v.equals(v.copy())  # AssertionError

with dask, equals returns True and the tests pass.

@keewis
Copy link
Collaborator

keewis commented Feb 19, 2020

equals returning False in the absence of dask is because of

if hasattr(np, "isnat") and (
dask_array is None or hasattr(dask_array_type, "__array_ufunc__")
):
# np.isnat is available since NumPy 1.13, so __array_ufunc__ is always
# supported.
isnat = np.isnat
else:
isnat = _dask_or_eager_func("isnull", eager_module=pd)
which uses np.isnat if dask is absent and pd.isnull if dask is present. Since dask_array_type is a tuple, hasattrwill always return False.

Wrapping a datetime in a quantity does not really make sense so I'll try to remove those tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants