-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Typingtype annotations, mypy/pyright type checkingtype annotations, mypy/pyright type checking
Milestone
Description
Problem description
pd.io.formats.format._binify
defines line_width
as Union[np.int32, int]
:
pandas/pandas/io/formats/format.py
Line 1893 in 39602e7
def _binify(cols: List[np.int32], line_width: Union[np.int32, int]) -> List[int]: |
however it is inconsistent with DataFrameFormatter.__init__
pandas/pandas/io/formats/format.py
Line 518 in 39602e7
class DataFrameFormatter(TableFormatter): |
and DataFrameFormatter._join_multiline
pandas/pandas/io/formats/format.py
Line 871 in 39602e7
col_bins = _binify(col_widths, lwidth) |
which take and pass as-is Optional[int]
.
This leads to Mypy error:
pandas/io/formats/format.py:871: error: Argument 2 to "_binify" has incompatible type "Optional[int]"; expected "Union[int32, int]"
Providing default in _join_multiline
, i.e.
lwidth = self.line_width or DEFAULT_LINE_WIDTH
could be reasonable fix. One could also ignore the call:
col_bins = _binify(col_widths, lwidth) # type: ignore
but that leaves possible correctness problem.
Expected Output
Passing Mypy type check
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit : bee17d5f4c99e6d1e451cf9a7b6a1780aa25988d
python : 3.7.3.final.0
...
Additionally
mypy==0.730
CC @WillAyd
Metadata
Metadata
Assignees
Labels
Typingtype annotations, mypy/pyright type checkingtype annotations, mypy/pyright type checking