-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[TYPING] pandas.io.formats.format._binify annotation is inconsistent with DataFrameFormatter.__init__ #28843
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
Comments
Cool thanks for taking a look! @simonjayhawkins as well Does the function actually fail if line_width is None? |
if i recall these types were from using MonkeyType. so if line_width is typed as Union[np.int32, int], then we have no tests that pass None. |
Haven't tested it, but I think it is safe to safe that it does fail on pandas/pandas/io/formats/format.py Line 1902 in 39602e7
and pandas/pandas/io/formats/format.py Line 1904 in 39602e7
|
Does import numpy as np
a_np_int = np.int32(32)
reveal_type(a_np_int) Wonder if we shouldn't just defer dealing with numpy types until they are actually annotated. Could just simplify this signature to be |
@WillAyd that's probably unrelated, but yes, all np.int to be replaced with python int is subsequent pass. |
i'm using 0.730, but not getting that particular mypy error show up yet on my branch. since there are many mypy errors, probably best to determine if it is an actual bug in the code, since we have mypy on the ci, and for the current options and version we have a passing build. typing errors will be resolved as more types are added and more strictness flags are enabled. |
Interesting... I downgraded Mypy to 0.730 and still get this one. Do you use any specific flags? |
see #28339 |
changing to and I get so the Any is swallowing the None. @zero323 do you have numpy stubs in your environment? |
i was wrong. |
Yes, I do. Edit: And once removed this error disappears hidden by some missing import. |
so I guess that adding stubs for all the missing imports becomes more important with PEP 561 compatibility since other users could have stubs for the other packages. |
From that point of view the problem with PEP 561 is that:
So effective outcome is rather hard to predict. Not to mention that all signs show that mature stubs for scientific stack are nowhere near. One possible workaround is to keep dynamic mock stubs that cover the part of the 3rd party API that you're interested in, and use these for internal testing. I had some luck with such approach in pyspark-stubs (mocking Pandas), but exposure there is relatively small. One way or another ignoring missing imports and |
Problem description
pd.io.formats.format._binify
definesline_width
asUnion[np.int32, int]
:pandas/pandas/io/formats/format.py
Line 1893 in 39602e7
however it is inconsistent with
DataFrameFormatter.__init__
pandas/pandas/io/formats/format.py
Line 518 in 39602e7
and
DataFrameFormatter._join_multiline
pandas/pandas/io/formats/format.py
Line 871 in 39602e7
which take and pass as-is
Optional[int]
.This leads to Mypy error:
Providing default in
_join_multiline
, i.e.could be reasonable fix. One could also ignore the call:
but that leaves possible correctness problem.
Expected Output
Passing Mypy type check
Output of
pd.show_versions()
Additionally
CC @WillAyd
The text was updated successfully, but these errors were encountered: