-
-
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 4 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 |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
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, | ||
|
||
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 +64,63 @@ 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): | ||
""" | ||
This test checks subraction of two DataArrays for the case | ||
when dimension is a structured array. | ||
""" | ||
# checking array subraction when dims are the same | ||
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)]) | ||
|
||
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, -4, -5], dims=['participant'], | ||
coords={'participant': p_data}) | ||
|
||
self.assertDataArrayIdentical(actual, expected) | ||
|
||
# checking array subraction when dims are not the same | ||
p_data_1 = np.array([('John', 180), ('Stacy', 151), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
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) | ||
|
||
# checking array subraction when dims are not the same and one | ||
# is np.nan | ||
p_data_1 = np.array([('John', 180), ('Stacy', np.nan), ('Dick', 200)], | ||
dtype=[('name', '|S256'), ('height', object)]) | ||
|
||
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.