Skip to content

BUG: Index.get_value implementation for ExtensionArray #29926

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

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche added ExtensionArray Extending pandas with custom dtypes or arrays. Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 29, 2019
@jorisvandenbossche jorisvandenbossche added this to the 1.0 milestone Nov 29, 2019
# array) the ExtensionArray unnecessary

def DecimalArray__array__(self, dtype=None):
raise Exception("tried to convert a DecimalArray to a numpy array")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not fully fool proof, as such an Exception could be catched somewhere in the indexing code. But I at least verified that for the s[s > 0.5] case, this test actually failed as desired before making the fix.

@jbrockmendel
Copy link
Member

The linked issue mentions densifying, which I think mostly affects SparseArray and Categorical. Would it make sense to test on those? Or is DecimalArray affected too?

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need a whatsnew note?

# See https://github.com/pandas-dev/pandas/issues/29708
# Ensure that indexing operations do not materialize (convert to a numpy
# array) the ExtensionArray unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this test more generic (e.g. hit more EA arrays)?

@jorisvandenbossche
Copy link
Member Author

The linked issue mentions densifying, which I think mostly affects SparseArray and Categorical. Would it make sense to test on those? Or is DecimalArray affected too?
..
can you make this test more generic (e.g. hit more EA arrays)?

For DecimalArray, converting to object array is indeed not a problem (it stores a numpy object array anyway), while for Categorical/Sparse this is more expensive. But it's the mechanism I want to test, and for that it doesn't matter much that it's not expensive for DecimalArray.

Making the test more generic (a base test so it is automatically run for all EAs) would be possible, but I am not sure it would be worth it: I would need to add several exceptions (overriding it in several places for certain dtypes to skip it: for sparse it still densifies (which is a separate issue), for numpy ones the test is not valid (it needs to convert to array), for interval it fails for another reason, for boolean is currently still converts to numpy array for the comparison operation, ...). And in the end, I mainly want to test the mechanism in the Index.get_value, which is not dependent on implementation details of the specific EA.

@jreback jreback merged commit 9a222ea into pandas-dev:master Dec 4, 2019
@jreback
Copy link
Contributor

jreback commented Dec 4, 2019

thanks

@jorisvandenbossche jorisvandenbossche deleted the GH29708-getitem-EA-materialize branch December 4, 2019 14:21
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexing (__getitem__) of DataFrame/Series with ExtensionArray densifies the array
3 participants