-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 19 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
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
Sequence, | ||
TypeVar, | ||
cast, | ||
overload, | ||
) | ||
|
||
import numpy as np | ||
|
@@ -15,6 +16,7 @@ | |
from pandas._typing import ( | ||
F, | ||
PositionalIndexer2D, | ||
PositionalIndexerTuple, | ||
Shape, | ||
type_t, | ||
) | ||
|
@@ -185,6 +187,17 @@ def __setitem__(self, key, value): | |
def _validate_setitem_value(self, value): | ||
return value | ||
|
||
@overload | ||
def __getitem__(self, key: int | np.integer) -> Any: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. isn't tihs a PositionScalar ? |
||
... | ||
|
||
@overload | ||
def __getitem__( | ||
self: NDArrayBackedExtensionArrayT, | ||
key: slice | np.ndarray | list[int] | PositionalIndexerTuple, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. First, there is no For the PositionalIndexer = Union[int, np.integer, slice, List[int], np.ndarray]
PositionalIndexerTuple = Tuple[PositionalIndexer, PositionalIndexer]
PositionalIndexer2D = Union[PositionalIndexer, PositionalIndexerTuple] For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh i had edited to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You mean "argument type", not "return type" ?? Here's the full code: @overload
def __getitem__(self, key: int | np.integer) -> Any:
...
@overload
def __getitem__(
self: NDArrayBackedExtensionArrayT,
key: slice | np.ndarray | list[int] | PositionalIndexerTuple,
) -> NDArrayBackedExtensionArrayT:
...
def __getitem__(
self: NDArrayBackedExtensionArrayT,
key: PositionalIndexer2D,
) -> NDArrayBackedExtensionArrayT | Any: The way it works is as follows with respect to the type of
This makes some downstream typing work correctly by creating the separation this way. |
||
) -> NDArrayBackedExtensionArrayT: | ||
... | ||
|
||
def __getitem__( | ||
self: NDArrayBackedExtensionArrayT, | ||
key: PositionalIndexer2D, | ||
|
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.
can you followup and give some hints on where these should be used (a.g. a line of description for each; example....)
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.
Done in a new commit - added comments - let me know if you want more
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.
got it, looks good.