-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
add test for 1D object array indexing #2415
Conversation
xarray/tests/test_indexing.py
Outdated
|
||
def test_indexing_1d_object_array(): | ||
testarray = DataArray(np.array((np.arange(3), np.arange(6)))) | ||
testarray[0] |
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.
Maybe add:
expected_array = np.empty((), dtype=object)
expected_array[()] = np.arange(3)
expected = DataArray(expected_array)
assert_identical(expected, testarray[0])
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.
Well...
I guess you mean:
expected_array = np.arange(3)
expected = DataArray(expected_array)
assert_identical(expected, testarray[0])
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.
expected_array = np.arange(3)
gives you an array with shape (3,)
and int dtype. You want a scalar NumPy with shape ()
and object dtype.
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.
OK, I get you point :-)
Main issue I still have then is that I'm not able to get the 'np.arange(3) array'
from the 'expected'...
because 'expected.data' is king of empty :-(
expected.data.shape == () therefore expected.data[0] raise an IndexError
How would you access the content of 'expected' ?
You could pull it out with expected.data.item()
…On Fri, Sep 14, 2018 at 12:43 AM David Trémouilles ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In xarray/tests/test_indexing.py
<#2415 (comment)>:
> @@ -622,3 +622,8 @@ def test_create_mask_error():
def test_posify_mask_subindexer(indices, expected):
actual = indexing._posify_mask_subindexer(indices)
np.testing.assert_array_equal(expected, actual)
+
+
+def test_indexing_1d_object_array():
+ testarray = DataArray(np.array((np.arange(3), np.arange(6))))
+ testarray[0]
OK, I get you point :-)
Main issue I still have then is that I'm not able to get the 'np.arange(3)
array'
from the 'expected'...
because 'expected.data' is king of empty :-(
expected.data.shape == () therefore expected.data[0] raise an IndexError
How would you access the content of 'expected' ?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2415 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABKS1uZNHXq96w2Dbt50Bw2uBHVxy00-ks5ua14TgaJpZM4Wnb0S>
.
|
if we still want this test, it should be ready for review / merging |
Let's do it! Thanks for resuscitating @keewis |
Thanks @keewis |
Test for issue #2414
closes #2414