Skip to content

Remove duck_array_ops.as_like_arrays() #3204

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

Merged
merged 3 commits into from
Aug 12, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -203,34 +193,27 @@ 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())


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())


Expand Down