-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Subset of "Improved the type stubs in the _libs directory to help with type checking" #44251
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
Hello @twoertwein! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-12-12 19:24:28 UTC |
# Union[Union[str, int, float, bool] Union[Period, Timestamp, Timedelta, Any]]]", | ||
# expected "Tuple[NumpyArrayT, Union[Union[str, int, float, bool], Union[Period, | ||
# Timestamp, Timedelta, Any]]]") | ||
return upcast_values, fill_value # type: ignore[return-value] |
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 probably be np.ndarray
and not be NumpyArrayT
since the dtype might change.
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 can change but the Python type (i.e. np.ndarray or subclass) maybe preserved. I'm not sure but the numpy types don't annotate as preserving Python object type so maybe not. This was added for ma.MaskedArray
handling in the constructors, so could well be that the numpy types are not precise enough, creating this false positive.
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.
looks ok to me. can you rebase @twoertwein
@simonjayhawkins @jbrockmendel if comments
cc @Dr-Irv |
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 see that you put some typing in the pandas/tests/tseries/...
. Have we started typing the test code, and running mypy
on parts of the test code?
If not, I don't think that should be included in the PR.
Some tests are typed checked, including those files.
The test changes I made are technically not needed for this PR. They will be needed for |
IMHO, I think the changes to the test files should be left out for now. That will make the PR smaller. But I would defer to @simonjayhawkins on this |
pandas/core/ops/mask_ops.py
Outdated
if left_mask is None: | ||
return kleene_xor(right, left, right_mask, left_mask) | ||
|
||
assert isinstance(left, np.ndarray) |
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 safe? @jbrockmendel The other kleene functions have it as 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.
holds in all of our current usages; to be future-safe would need to change this to a check that raises TypeError
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.
it raises now a TypeError
looks good, can you rebase @simonjayhawkins if any comments. |
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 @twoertwein
# Union[Union[str, int, float, bool] Union[Period, Timestamp, Timedelta, Any]]]", | ||
# expected "Tuple[NumpyArrayT, Union[Union[str, int, float, bool], Union[Period, | ||
# Timestamp, Timedelta, Any]]]") | ||
return upcast_values, fill_value # type: ignore[return-value] |
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 can change but the Python type (i.e. np.ndarray or subclass) maybe preserved. I'm not sure but the numpy types don't annotate as preserving Python object type so maybe not. This was added for ma.MaskedArray
handling in the constructors, so could well be that the numpy types are not precise enough, creating this false positive.
The test modules are type checked but the test functions are not (check_untyped_defs is False). Saying that we have several test modules ignored in the mypy config |
@twoertwein can you merge master |
thanks @twoertwein very nice |
The two big parts missing from #43744 are interval.pyi and offsets.pyi as they result in many mypy errors.
I had already made changes to somewhat accommodate for interval.pyi and offsets.pyi (if these files are included, we have now "only" ~100 mypy errors). I kept these changes in this PR.