-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: overload lib.maybe_convert_objects #41166
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
Conversation
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.
There's a part (which I've commented on) where I haven't understood why mypy
is reporting an error - on than that, this looks good to me
pandas/core/strings/object_array.py
Outdated
# error: Argument 1 to "ndarray" has incompatible type "int"; | ||
# expected "Sequence[int]" | ||
return np.ndarray(0, dtype=dtype) # type: ignore[arg-type] | ||
# error: Argument "dtype" to "array" has incompatible type | ||
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected | ||
# "Union[dtype[Any], None, type, _SupportsDType, str, | ||
# Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any], | ||
# _DTypeDict, Tuple[Any, Any]]]" | ||
return np.array([], dtype=dtype) # type: ignore[arg-type] |
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.
I'm confused about why mypy
reports this, if I try making a file t.py
with
import numpy as np
from pandas._typing import Dtype, Optional
def foo(dtype: Optional[Dtype] = None):
if dtype is None:
dtype = np.dtype("object")
return (np.array([], dtype=type))
then mypy
type checks it just fine. Do you know what I might be missing?
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.
no idea. i think this edit is unrelated to most of the rest; using np.ndarray
here instead of np.array
weirds me out
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.
The Dtype
alias includes ExtensionDtype
which cannot be passed on to numpy
>>> np.array([], dtype=pd.Int64Dtype())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot interpret 'Int64Dtype()' as a data type
>>>
Do you know what I might be missing?
return (np.array([], dtype=type))
-> return (np.array([], dtype=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.
I'm embarrassed, thanks!
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.
so this looks like there maybe an actual bug here. As part of the ArrowStringArray work, I have been parameterising existing tests on object dtype arrays with StringArray and ArrowStringArray and this has maybe uncovered some latent bugs with StringArray.
I think OK to leave this ignore as a 'fix later' and out of scope here.
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.
Thanks @jbrockmendel generally lgtm
new_values, _ = func( | ||
self.to_numpy(object), # type: ignore[arg-type] | ||
self.to_numpy("object"), |
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.
This is an unrelated change to the scope (from the PR title) of this PR. The mypy error is a false positive, no need to change code. will be fixed in #41185
but I guess nbd (other than merge conflicts)
pandas/core/strings/object_array.py
Outdated
# error: Argument 1 to "ndarray" has incompatible type "int"; | ||
# expected "Sequence[int]" | ||
return np.ndarray(0, dtype=dtype) # type: ignore[arg-type] | ||
# error: Argument "dtype" to "array" has incompatible type | ||
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected | ||
# "Union[dtype[Any], None, type, _SupportsDType, str, | ||
# Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any], | ||
# _DTypeDict, Tuple[Any, Any]]]" | ||
return np.array([], dtype=dtype) # type: ignore[arg-type] |
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.
so this looks like there maybe an actual bug here. As part of the ArrowStringArray work, I have been parameterising existing tests on object dtype arrays with StringArray and ArrowStringArray and this has maybe uncovered some latent bugs with StringArray.
I think OK to leave this ignore as a 'fix later' and out of scope here.
pandas/core/tools/datetimes.py
Outdated
# error: Incompatible types in assignment (expression has type "None", variable has | ||
# type "ExtensionArray") | ||
result = None # type: ignore[assignment] | ||
result = None |
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.
is this needed? The if result is None
will always be True?
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.
Thanks @jbrockmendel lgtm
No description provided.