Skip to content

Conversation

@phofl
Copy link
Member

@phofl phofl commented Dec 10, 2022

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Dec 10, 2022
Copy link
Contributor

@topper-123 topper-123 left a comment

Choose a reason for hiding this comment

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

See also my more general comment about using IntegerArrays in .iloc in #49521.

df = DataFrame([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
result = df.iloc[Series([1], dtype="Int64"), Series([0, 1], dtype="Int64")]
expected = DataFrame([[5, 6]], index=[1])
tm.assert_frame_equal(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty suire this would fail if a pd.NA was in the indexers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep it does, which is fine. Will add a test

elif is_list_like_indexer(key):
arr = np.array(key)
if isinstance(key, ABCSeries):
arr = key._values
Copy link
Contributor

Choose a reason for hiding this comment

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

How about integer arrays with pd.NA?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is validated later

Copy link
Contributor

@topper-123 topper-123 Dec 11, 2022

Choose a reason for hiding this comment

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

The errors are different for Series and IntegerArray:

>>> import pandas as pd
>>> df = pd.DataFrame([[0,1,2,3,4],[5,6,7,8,9]])
>>> iarr = pd.array([0,1,2, pd.NA], dtype = pd.Int64Dtype())
>>> df.iloc[:, iarr]
IndexError: .iloc requires numeric indexers, got [0 1 2 <NA>]
df.iloc[:, pd.Series(iarr)]
ValueError: cannot convert to 'int64'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.

I think the ValueError should be raised in both cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess you tried the series case on main? I am getting consistent errors on my pr.

In General I would prefer a better suited error, pointing to NA in iloc. But will probably do in a follow up. We will have to check this later, because not all cases get here and this does not cover the series.iloc case

Copy link
Contributor

@topper-123 topper-123 Dec 11, 2022

Choose a reason for hiding this comment

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

Sorry wrong snippet. It's the non-NA array:

>>> import pandas as pd
>>> df = pd.DataFrame([[0,1,2,3,4],[5,6,7,8,9]])
>>> iarr = pd.array([0,1,2], dtype = pd.Int64Dtype())
>>> df.iloc[:, iarr]
IndexError: .iloc requires numeric indexers, got [0 1]

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah got you, fixed that as well

@mroeschke mroeschke added this to the 2.0 milestone Dec 13, 2022
@mroeschke mroeschke merged commit e476938 into pandas-dev:main Dec 13, 2022
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the 49521 branch December 13, 2022 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Indexing Related to indexing on series/frames, not to indexes themselves NA - MaskedArrays Related to pd.NA and nullable extension arrays

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: IndexError: .iloc requires numeric indexers, got [0 1 2 3]

3 participants