-
-
Notifications
You must be signed in to change notification settings - Fork 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
Fixed a bug that showed when trying to establish equivalence of two a… #837
Changes from 3 commits
f9c51b7
6635f9c
ee3a23e
16a7c37
96af68c
b8beca4
c0b97b1
693d019
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,18 @@ def array_equiv(arr1, arr2): | |
arr1, arr2 = as_like_arrays(arr1, arr2) | ||
if arr1.shape != arr2.shape: | ||
return False | ||
return bool(((arr1 == arr2) | (isnull(arr1) & isnull(arr2))).all()) | ||
|
||
flag_array = (arr1 == arr2) | ||
try: | ||
|
||
flag_array |= (isnull(arr1) & isnull(arr2)) | ||
|
||
except TypeError: | ||
pass | ||
|
||
return bool(flag_array.all()) | ||
|
||
# return bool(((arr1 == arr2) | (isnull(arr1) & isnull(arr2))).all()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out lines |
||
|
||
|
||
def _call_possibly_missing_method(arg, name, args, kwargs): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,10 @@ | |
Coordinate, Variable) | ||
from xarray.core.pycompat import iteritems, OrderedDict | ||
from xarray.core.common import _full_like | ||
from . import (TestCase, ReturnItem, source_ndarray, unittest, requires_dask, | ||
# from . import (TestCase, ReturnItem, source_ndarray, unittest, requires_dask, | ||
# requires_bottleneck) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this commented out code. |
||
from xarray.test import (TestCase, ReturnItem, source_ndarray, unittest, requires_dask, | ||
requires_bottleneck) | ||
|
||
|
||
|
@@ -63,6 +66,67 @@ def test_data_property(self): | |
self.assertArrayEqual(2 * np.ones((3, 4)), actual.data) | ||
self.assertArrayEqual(actual.data, actual.values) | ||
|
||
def test_struct_array_dims(self): | ||
# -----------------test 1 | ||
p_data = np.array([('John', 180), ('Stacy', 150), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
p_data_1 = np.array([('John', 180), ('Stacy', 150), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
weights_0 = DataArray([80, 56, 120], dims=['participant'], | ||
coords={'participant': p_data}) | ||
weights_1 = DataArray([81, 52, 115], dims=['participant'], | ||
coords={'participant': p_data_1}) | ||
|
||
actual = weights_1 - weights_0 | ||
|
||
expected = DataArray([1, -4, -5], dims=['participant'], | ||
coords={'participant': p_data}) | ||
|
||
self.assertDataArrayIdentical(actual, expected) | ||
|
||
# -----------------test 2 | ||
p_data = np.array([('John', 180), ('Stacy', 150), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
p_data_1 = np.array([('John', 180), ('Stacy', 151), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
p_data_2 = np.array([('John', 180), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
weights_0 = DataArray([80, 56, 120], dims=['participant'], | ||
coords={'participant': p_data}) | ||
weights_1 = DataArray([81, 52, 115], dims=['participant'], | ||
coords={'participant': p_data_1}) | ||
|
||
actual = weights_1 - weights_0 | ||
|
||
expected = DataArray([1, -5], dims=['participant'], | ||
coords={'participant': p_data_2}) | ||
|
||
self.assertDataArrayIdentical(actual, expected) | ||
|
||
# -----------------test 3 - np.nan | ||
p_data = np.array([('John', 180), ('Stacy', 150), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
p_data_1 = np.array([('John', 180), ('Stacy', np.nan), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
p_data_2 = np.array([('John', 180), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
weights_0 = DataArray([80, 56, 120], dims=['participant'], | ||
coords={'participant': p_data}) | ||
weights_1 = DataArray([81, 52, 115], dims=['participant'], | ||
coords={'participant': p_data_1}) | ||
|
||
actual = weights_1 - weights_0 | ||
|
||
expected = DataArray([1, -5], dims=['participant'], | ||
coords={'participant': p_data_2}) | ||
|
||
self.assertDataArrayIdentical(actual, expected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the tests you've written are overly verbose. I don't think you need to recreate |
||
def test_name(self): | ||
arr = self.dv | ||
self.assertEqual(arr.name, 'foo') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a brief comment explaining why we allow
TypeError
here? a reference to this issue (e.g.,GH837
)` could be nice, too.