Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TYP: Typing for ExtensionArray.__getitem__ #41258
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
TYP: Typing for ExtensionArray.__getitem__ #41258
Changes from 6 commits
6c83511
0c8d648
c43eadc
94ced76
4772f8e
2773c8b
b7f2485
01c0cf5
3b38de2
b25d5a3
d7c545d
076e434
01c1a3f
738ec89
c5e300c
1dbb668
3e19841
73680ac
adf3a73
6068976
0f36e5f
9557cac
9a8550d
10c454d
a5318bc
b941732
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for this PR, but could/should we do a Generic think to tighten this Any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. Should I create an issue for discussion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't tihs a PositionScalar ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this PostionalIndexer2D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, there is no
PositionScalar
, so I'm not sure what you are referring to.For the
NDArrayBackedExtensionArray
, which extendsExtensionArray
,__getitem__()
needs to handle the__getitem__()
arguments forExtensionArray
, which isPositionalIndexer
, and thenNDArrayBackedExtensionArray
can widen the accepted arguments. We then haveFor
NDArrayBackedExtensionArray.__getitem__()
, it acceptsPositionalIndexer2D
. The overloads then indicate what are the return types for the various subtypes ofPositionalIndexer2D
. This has separate return types if the arguments areint | np.integer
versusslice | np.ndarray | list[int] | PositionalIndexerTuple
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i had edited to
PositionalIndexer2D
which looks like the correct return type hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean "argument type", not "return type" ??
Here's the full code:
The way it works is as follows with respect to the type of
key
:int | np.integer
, return type isAny
slice | np.ndarray | list[int] | PositionalIndexerTuple
, return type is definitelyNDArrayBackedExtensionArrayT
PositionalIndexer
, return type is eitherNDArrayBackedExtensionArrayT | Any
This makes some downstream typing work correctly by creating the separation this way.