Skip to content
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

Merged
merged 7 commits into from
Apr 5, 2021
Merged

Conversation

davidtrem
Copy link
Contributor

@davidtrem davidtrem commented Sep 13, 2018

Test for issue #2414

closes #2414


def test_indexing_1d_object_array():
testarray = DataArray(np.array((np.arange(3), np.arange(6))))
testarray[0]
Copy link
Member

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

Copy link
Contributor Author

@davidtrem davidtrem Sep 13, 2018

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

Copy link
Member

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.

Copy link
Contributor Author

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' ?

xarray/tests/test_indexing.py Show resolved Hide resolved
@shoyer
Copy link
Member

shoyer commented Sep 14, 2018 via email

@keewis
Copy link
Collaborator

keewis commented Apr 3, 2021

if we still want this test, it should be ready for review / merging

@max-sixty
Copy link
Collaborator

Let's do it! Thanks for resuscitating @keewis

@dcherian
Copy link
Contributor

dcherian commented Apr 5, 2021

Thanks @keewis

@dcherian dcherian merged commit 27ecf2d into pydata:master Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexing not properly working with object dtype element ?
6 participants