-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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: remove mypy ignore[assignment] from pandas/core/internals/construction.py #53135
TYP: remove mypy ignore[assignment] from pandas/core/internals/construction.py #53135
Conversation
Hi @MarcoGorelli, could you please take a look at this pr? |
# Incompatible types in assignment (expression has type | ||
# "List[Union[ExtensionArray, ndarray[Any, Any], None]]", variable | ||
# has type "List[Union[ExtensionArray, ndarray[Any, Any]]]") | ||
arrays = new_arrays # type: ignore[assignment] | ||
arrays = cast(list[ArrayLike], new_arrays) |
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 it possible to refactor instead of casting? it might be possible to be more precise here
something like
new_arrays: list[ArrayLike] = []
indexer = arr_columns.get_indexer(columns)
for i, k in enumerate(indexer):
if k == -1:
# by convention default is all-NaN object dtype
arr = np.empty(length, dtype=object)
arr.fill(np.nan)
else:
arr = arrays[k]
new_arrays.append(arr)
then the cast might not be necessary? haven't tried running this (currently on a train 🚋), but hoping this might work
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.
Thank you, I did as you suggested. It works very well.
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.
should be good, lgtm on green, thanks @natmokval!
let's ship it if you're interested in typing, I'd highly suggest you take a look at https://github.com/pandas-dev/pandas-stubs - that affects the type hints which users get, there's plenty of really useful issues to work on there (and feel free to reach out to Irv if you're not sure where to start) |
…uction.py (pandas-dev#53135) * remove mypy ignore[assignment] * replace casting with refactoring
…uction.py (pandas-dev#53135) * remove mypy ignore[assignment] * replace casting with refactoring
Related to #37715
mypy ignore[assignment] was removed from pandas/core/internals/construction.py