Skip to content

Conversation

@Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Apr 18, 2022

Allow DataFrame.iloc to accept lists, etc. that produce a DataFrame

np_ndarray_bool = npt.NDArray[np.bool_]
np_ndarray_str = npt.NDArray[np.str_]
IndexType = Union[slice, np_ndarray_int64, Index, List[int], Series[int]]
MaskType = Union[Series[bool], np_ndarray_bool, Sequence[bool]]
Copy link
Member

Choose a reason for hiding this comment

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

This change doesn't make sense to me. A List is a Sequence, and Sequence is preferred when typing args. Where you having issues with the way it was?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sequence includes Tuple, and we have to differentiate those cases in pandas.

If you do df.iloc[3,4], the argument is a tuple, and returns a scalar. If you do df.iloc[[3,4]], the argument is a list, and returns a DataFrame. Sequence matches both cases. Also, Sequence matches a str, which is painful in other contexts.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for clarifying. I think when I created these a lot of the time the docs said things like "list-like" and those I went and made Sequence.

@gramster gramster merged commit edc791f into microsoft:main Apr 20, 2022
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.

2 participants