-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: check_untyped_defs core.indexes.base #36924
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
pandas/io/formats/printing.py
Outdated
@@ -503,7 +505,7 @@ def _justify( | |||
|
|||
|
|||
def format_object_attrs( | |||
obj: Sequence, include_dtype: bool = True | |||
obj: Union[Sequence, AnyArrayLike], include_dtype: bool = 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.
AnyArrayLike doesnt satisfy Sequence?
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.
not at the moment, xref #28770
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 looks like the issue here actually is that the docstring states iterable, but len is used in the function code and is the only requirement.
>>> from pandas.io.formats.printing import format_object_attrs
>>>
>>> format_object_attrs(pd.array([1, 2, 3] * 100, dtype="Int64"))
[('dtype', "'Int64'"), ('length', 300)]
>>>
>>> format_object_attrs(pd.Index([1, 2, 3] * 100))
[('dtype', "'int64'"), ('length', 300)]
>>>
>>> format_object_attrs("foo" * 100)
[('length', 300)]
>>>
>>> class MyClass:
... def __len__(self):
... return 300
...
>>> format_object_attrs(MyClass())
[('length', 300)]
>>>
>>> format_object_attrs(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\simon\Anaconda3\envs\pandas-1.1.2\lib\site-packages\pandas\io\formats\printing.py", line 536, in format_object_attrs
if len(obj) > max_seq_items:
TypeError: object of type 'int' has no len()
>>>
I'll type as Sized for now to be as permissive as possible to faciliate re-usability, but AFAICT, format_object_attrs is only ever called with an Index.
(so alternatively could just use Index as type for obj, and maybe reduce the hasattr usages or replace with isinstance(obj, MultiIndex))
can you rebase |
restarted the (clearly-unrelated) failing build. AFAICT on windows |
LGTM cc @jreback |
thanks @simonjayhawkins really like this cleaning & checking of untyped defs, keep em coming! |
pandas\core\indexes\base.py:975: error: Argument 1 to "format_object_attrs" has incompatible type "Index"; expected "Sequence[Any]" [arg-type]
pandas\core\indexes\base.py:1612: error: "Index" has no attribute "levels"; maybe "nlevels"? [attr-defined]
pandas\core\indexes\base.py:1613: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:3763: error: "Index" has no attribute "levels"; maybe "nlevels"? [attr-defined]
pandas\core\indexes\base.py:3779: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:3787: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:3790: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:3793: error: "Index" has no attribute "levels"; maybe "nlevels"? [attr-defined]
pandas\core\indexes\base.py:3837: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:3840: error: "Index" has no attribute "codes" [attr-defined]
pandas\core\indexes\base.py:4807: error: Too many arguments for "get_indexer_non_unique" of "Index" [call-arg]
pandas\core\indexes\base.py:5403: error: Cannot assign to a method [assignment]
pandas\core\indexes\base.py:5404: error: Cannot assign to a method [assignment]
pandas\core\indexes\base.py:5405: error: Unsupported left operand type for < ("Type[Index]") [operator]
pandas\core\indexes\base.py:5406: error: Unsupported left operand type for > ("Type[Index]") [operator]
pandas\core\indexes\base.py:5407: error: Unsupported left operand type for <= ("Type[Index]") [operator]
pandas\core\indexes\base.py:5408: error: Unsupported left operand type for >= ("Type[Index]") [operator]
pandas\core\indexes\base.py:5415: error: Unsupported left operand type for + ("Type[Index]") [operator]
pandas\core\indexes\base.py:5416: error: "Type[Index]" has no attribute "radd" [attr-defined]
pandas\core\indexes\base.py:5417: error: Unsupported left operand type for - ("Type[Index]") [operator]
pandas\core\indexes\base.py:5418: error: "Type[Index]" has no attribute "rsub" [attr-defined]
pandas\core\indexes\base.py:5419: error: "Type[Index]" has no attribute "rpow" [attr-defined]
pandas\core\indexes\base.py:5420: error: Unsupported left operand type for ** ("Type[Index]") [operator]
pandas\core\indexes\base.py:5422: error: Unsupported left operand type for / ("Type[Index]") [operator]
pandas\core\indexes\base.py:5423: error: "Type[Index]" has no attribute "rtruediv" [attr-defined]
pandas\core\indexes\base.py:5425: error: Unsupported left operand type for % ("Type[Index]") [operator]
pandas\core\indexes\base.py:5426: error: "Type[Index]" has no attribute "rmod" [attr-defined]
pandas\core\indexes\base.py:5427: error: Unsupported left operand type for // ("Type[Index]") [operator]
pandas\core\indexes\base.py:5428: error: "Type[Index]" has no attribute "rfloordiv" [attr-defined]
pandas\core\indexes\base.py:5429: error: Unsupported left operand type for divmod ("Type[Index]") [operator]
pandas\core\indexes\base.py:5430: error: "Type[Index]" has no attribute "rdivmod" [attr-defined]
pandas\core\indexes\base.py:5431: error: Unsupported left operand type for * ("Type[Index]") [operator]
pandas\core\indexes\base.py:5432: error: "Type[Index]" has no attribute "rmul" [attr-defined]
pandas\core\indexes\base.py:5449: error: Unsupported operand type for unary - ("Type[Index]") [operator]
pandas\core\indexes\base.py:5450: error: Unsupported operand type for unary + ("Type[Index]") [operator]
pandas\core\indexes\base.py:5451: error: "Type[Index]" has no attribute "abs" [attr-defined]
pandas\core\indexes\base.py:5452: error: "Type[Index]" has no attribute "inv" [attr-defined]
pandas\core\indexes\base.py:5564: error: "Type[Index]" has no attribute "all" [attr-defined]
pandas\core\indexes\base.py:5567: error: "Type[Index]" has no attribute "any" [attr-defined]
pandas\core\indexes\base.py:5576: error: "Type[Index]" has no attribute "all" [attr-defined]
pandas\core\indexes\base.py:5577: error: "Type[Index]" has no attribute "any" [attr-defined]