-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Fix typing for extension arrays and extension dtypes without isin and astype #40421
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 1 commit
f2c52a4
d7ff8d3
49fa06e
03b2c4a
3e19958
6861901
9be6486
260b367
6276725
4dafaca
8b2cee2
3a7d839
a21bb60
8cd6b76
e0e0131
6a6a21f
bf753e6
c9795a5
d452842
3c2c78b
548c198
db8ed9b
f8191f8
575645f
6f8fcb5
3ea2420
c83a628
5bb24d4
ad1ab3b
63c3d6d
1882074
1274a76
363e203
01c942c
1196132
66d5da4
5411998
9b7481d
4bd3422
3b1ff79
5719daa
dbfb3a2
d41bf91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,15 +525,7 @@ def nbytes(self) -> int: | |
# ------------------------------------------------------------------------ | ||
# Additional Methods | ||
# ------------------------------------------------------------------------ | ||
@overload | ||
def astype(self, dtype: Type[str], copy: bool = True) -> np.ndarray: | ||
... | ||
|
||
@overload | ||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
... | ||
|
||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
def astype(self, dtype: Dtype, copy: bool = True): | ||
""" | ||
Cast to a NumPy array with 'dtype'. | ||
|
||
|
@@ -933,7 +925,9 @@ def isin(self, values: Sequence[Any]) -> np.ndarray: | |
------- | ||
np.ndarray[bool] | ||
""" | ||
return isin(self.astype(object), values) | ||
# error: Argument 2 to "isin" has incompatible type "Sequence[Any]"; expected | ||
# "Union[Union[ExtensionArray, ndarray], Index, Series]" | ||
return isin(self.astype(object), values) # type: ignore[arg-type] | ||
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. can you avoid adding this ignore. i.e. make the types of EA.isin and algos.isin consistent. |
||
|
||
def _values_for_factorize(self) -> Tuple[np.ndarray, Any]: | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
Tuple, | ||
Type, | ||
Union, | ||
overload, | ||
) | ||
import warnings | ||
|
||
|
@@ -381,14 +380,6 @@ def reconstruct(x): | |
def _coerce_to_array(self, value) -> Tuple[np.ndarray, np.ndarray]: | ||
return coerce_to_array(value) | ||
|
||
@overload | ||
def astype(self, dtype: Type[str], copy: bool = True) -> np.ndarray: | ||
... | ||
|
||
@overload | ||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
... | ||
|
||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
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. astype changes are going to be a separate PR. revert for now |
||
""" | ||
Cast to a NumPy array or ExtensionArray with 'dtype'. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
Optional, | ||
Tuple, | ||
Type, | ||
overload, | ||
) | ||
import warnings | ||
|
||
|
@@ -279,14 +278,6 @@ def _from_sequence_of_strings( | |
def _coerce_to_array(self, value) -> Tuple[np.ndarray, np.ndarray]: | ||
return coerce_to_array(value, dtype=self.dtype) | ||
|
||
@overload | ||
def astype(self, dtype: Type[str], copy: bool = True) -> np.ndarray: | ||
... | ||
|
||
@overload | ||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
... | ||
|
||
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | ||
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. same |
||
""" | ||
Cast to a NumPy array or ExtensionArray with 'dtype'. | ||
|
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.
when adding types, we should ensure that the types match the docstrings. From the PR title and previous discussion, IIUC astype was being done separately.
I would revert this for now until this method is sorted properly.
see also #41018 (comment) and response.
The docstring states we return np.ndarray and the one-liner suggests that too. We sometimes also return an ExtensionArray, this is dependent on the type of dtype.
my concern is that if we add the type now, this may get forgotten.