-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: remove mypy ignore from array_manager.py #52249
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 from array_manager.py #52249
Conversation
# error: Incompatible types in assignment (expression has type "ndarray", | ||
# variable has type "range") | ||
indices = np.nonzero(loc)[0] # type: ignore[assignment] | ||
indices = np.array([i for i in range(len(loc)) if loc[i] is 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.
I think you would need to change line 837 to indices : range | np.ndarray = range(
Mypy uses early binding, the if block declares the variable for the first time with type range
. When mypy parses the else block, it thinks the type should be range and not np.ndarray. I believe pyright doesn't do that (for each block it uses its own type and then uses the union after an if/else)
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 think you would need to change line 837 to
indices : range | np.ndarray = range(
Thank you for the comment. I did as you suggested.
Mypy uses early binding, the if block declares the variable for the first time with type
range
. When mypy parses the else block, it thinks the type should be range and not np.ndarray. I believe pyright doesn't do that (for each block it uses its own type and then uses the union after an if/else)
Could it be the reason why locally I didn't have a failure in test_dup_across_dtypes(self)
, but in ci there was an error in the same function in line pandas/tests/frame/test_nonunique_indexes.py:147:
?
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.
Could it be the reason why locally I didn't have a failure in
test_dup_across_dtypes(self)
, but in ci there was an error in the same function in linepandas/tests/frame/test_nonunique_indexes.py:147:
?
The type annotations shouldn't cause a test to fail at runtime. I'm not familiar with the test but I assume that the code changes from your previous commits might have changed the runtime behavior which triggered some tests to fail.
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, I get it. np.nonzero works much more effectively regarding time than my code changes.
5b850ac
to
73c4ad7
Compare
Thanks @natmokval |
Related to #37715
mypy ignore was removed from pandas/core/internals/array_manager.py