diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index b2b6077c67f..3d7e7cc64bc 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -180,21 +180,11 @@ def as_shared_dtype(scalars_or_arrays): return [x.astype(out_type, copy=False) for x in arrays] -def as_like_arrays(*data): - if all(isinstance(d, dask_array_type) for d in data): - return data - elif any(isinstance(d, sparse_array_type) for d in data): - from sparse import COO - - return tuple(COO(d) for d in data) - else: - return tuple(np.asarray(d) for d in data) - - def allclose_or_equiv(arr1, arr2, rtol=1e-5, atol=1e-8): """Like np.allclose, but also allows values to be NaN in both arrays """ - arr1, arr2 = as_like_arrays(arr1, arr2) + arr1 = asarray(arr1) + arr2 = asarray(arr2) if arr1.shape != arr2.shape: return False return bool(isclose(arr1, arr2, rtol=rtol, atol=atol, equal_nan=True).all()) @@ -203,16 +193,13 @@ def allclose_or_equiv(arr1, arr2, rtol=1e-5, atol=1e-8): def array_equiv(arr1, arr2): """Like np.array_equal, but also allows values to be NaN in both arrays """ - arr1, arr2 = as_like_arrays(arr1, arr2) + arr1 = asarray(arr1) + arr2 = asarray(arr2) if arr1.shape != arr2.shape: return False - with warnings.catch_warnings(): warnings.filterwarnings("ignore", "In the future, 'NAT == x'") - - flag_array = arr1 == arr2 - flag_array |= isnull(arr1) & isnull(arr2) - + flag_array = (arr1 == arr2) | (isnull(arr1) & isnull(arr2)) return bool(flag_array.all()) @@ -220,17 +207,13 @@ def array_notnull_equiv(arr1, arr2): """Like np.array_equal, but also allows values to be NaN in either or both arrays """ - arr1, arr2 = as_like_arrays(arr1, arr2) + arr1 = asarray(arr1) + arr2 = asarray(arr2) if arr1.shape != arr2.shape: return False - with warnings.catch_warnings(): warnings.filterwarnings("ignore", "In the future, 'NAT == x'") - - flag_array = arr1 == arr2 - flag_array |= isnull(arr1) - flag_array |= isnull(arr2) - + flag_array = (arr1 == arr2) | isnull(arr1) | isnull(arr2) return bool(flag_array.all()) diff --git a/xarray/tests/test_sparse.py b/xarray/tests/test_sparse.py index 4014d8a66e6..863c26661ff 100644 --- a/xarray/tests/test_sparse.py +++ b/xarray/tests/test_sparse.py @@ -99,16 +99,13 @@ def test_variable_property(prop): (do("all"), False), (do("any"), False), (do("astype", dtype=int), True), - (do("broadcast_equals", make_xrvar({"x": 10, "y": 5})), False), (do("clip", min=0, max=1), True), (do("coarsen", windows={"x": 2}, func=np.sum), True), (do("compute"), True), (do("conj"), True), (do("copy"), True), (do("count"), False), - (do("equals", make_xrvar({"x": 10, "y": 5})), False), (do("get_axis_num", dim="x"), False), - (do("identical", other=make_xrvar({"x": 10, "y": 5})), False), (do("isel", x=slice(2, 4)), True), (do("isnull"), True), (do("load"), True), @@ -121,6 +118,21 @@ def test_variable_property(prop): (do("to_base_variable"), True), (do("transpose"), True), (do("unstack", dimensions={"x": {"x1": 5, "x2": 2}}), True), + param( + do("broadcast_equals", make_xrvar({"x": 10, "y": 5})), + False, + marks=xfail(reason="https://github.com/pydata/sparse/issues/270"), + ), + param( + do("equals", make_xrvar({"x": 10, "y": 5})), + False, + marks=xfail(reason="https://github.com/pydata/sparse/issues/270"), + ), + param( + do("identical", make_xrvar({"x": 10, "y": 5})), + False, + marks=xfail(reason="https://github.com/pydata/sparse/issues/270"), + ), param( do("argmax"), True, @@ -349,7 +361,6 @@ def test_dataarray_property(prop): (do("assign_attrs", {"foo": "bar"}), True), (do("assign_coords", x=make_xrarray({"x": 10}).x + 1), True), (do("astype", int), True), - (do("broadcast_equals", make_xrarray({"x": 10, "y": 5})), False), (do("clip", min=0, max=1), True), (do("compute"), True), (do("conj"), True), @@ -357,7 +368,6 @@ def test_dataarray_property(prop): (do("count"), False), (do("diff", "x"), True), (do("drop", "x"), True), - (do("equals", make_xrarray({"x": 10, "y": 5})), False), (do("expand_dims", {"z": 2}, axis=2), True), (do("get_axis_num", "x"), False), (do("get_index", "x"), False), @@ -380,10 +390,18 @@ def test_dataarray_property(prop): (do("stack", z={"x", "y"}), True), (do("transpose"), True), # TODO - # isel_points - # sel_points # set_index # swap_dims + param( + do("broadcast_equals", make_xrvar({"x": 10, "y": 5})), + False, + marks=xfail(reason="https://github.com/pydata/sparse/issues/270"), + ), + param( + do("equals", make_xrvar({"x": 10, "y": 5})), + False, + marks=xfail(reason="https://github.com/pydata/sparse/issues/270"), + ), param( do("argmax"), True,