Skip to content

Extend Scalar sub-type of Index to the __iter__() method #367

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
merged 1 commit into from
Dec 5, 2022

Conversation

gandhis1
Copy link
Contributor

@gandhis1 gandhis1 commented Oct 6, 2022

As mentioned in that issue, I am a little bit confused about what the type of a column or index label is.....feels like in some places we decided it is a Hashable and in other places we decided it's a Scalar. But just to stay consistent with the way this was already annotated, I continued to use Scalar.

@gandhis1 gandhis1 marked this pull request as draft October 20, 2022 02:47
@gandhis1 gandhis1 force-pushed the index branch 2 times, most recently from 3190539 to 0f5c899 Compare November 6, 2022 03:30
@@ -497,8 +497,7 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def __getitem__(
self,
idx: tuple
| Series[_bool]
idx: Series[_bool]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

x = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=["a", "b", "c"])

   0  1  2
a  1  2  3
b  4  5  6
c  7  8  9

x[[0, 1]] works

x[(0, 1)] does not, because that is interpreted as a column label

@gandhis1
Copy link
Contributor Author

gandhis1 commented Nov 6, 2022

So it appears NDArray is being treated as a Hashable, which creates overlapping overloads per MyPy. I don't see any way to fix this currently.

So I took a different approach. Went back to annotating using Scalar, but then augmenting that Union with a Tuple[Scalar, ...]. I added some tests to illustrate some of the edge cases. There is one old test that is failing, and not sure what the best course of action there is, I added a note.

@gandhis1 gandhis1 force-pushed the index branch 2 times, most recently from ce62af9 to 4337b8d Compare November 26, 2022 17:22
@gandhis1 gandhis1 marked this pull request as ready for review December 3, 2022 22:31
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @gandhis1

@Dr-Irv Dr-Irv merged commit bc61543 into pandas-dev:main Dec 5, 2022
@Dr-Irv Dr-Irv mentioned this pull request Feb 10, 2023
1 task
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.

DataFrame columns should return a type containing Hashable (or Scalar?) elements
2 participants