Skip to content
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: check_untyped_defs core.indexes.base #36924

Merged
merged 6 commits into from
Oct 10, 2020

Conversation

simonjayhawkins
Copy link
Member

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]

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Oct 6, 2020
@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Oct 6, 2020
@@ -503,7 +505,7 @@ def _justify(


def format_object_attrs(
obj: Sequence, include_dtype: bool = True
obj: Union[Sequence, AnyArrayLike], include_dtype: bool = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnyArrayLike doesnt satisfy Sequence?

Copy link
Member Author

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

Copy link
Member Author

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))

@jreback
Copy link
Contributor

jreback commented Oct 7, 2020

can you rebase

@jbrockmendel
Copy link
Member

restarted the (clearly-unrelated) failing build. AFAICT on windows LinePlot._is_ts_plot is messing up, but no insight as to why

@jbrockmendel
Copy link
Member

LGTM cc @jreback

@jreback jreback merged commit f572faf into pandas-dev:master Oct 10, 2020
@jreback
Copy link
Contributor

jreback commented Oct 10, 2020

thanks @simonjayhawkins really like this cleaning & checking of untyped defs, keep em coming!

@simonjayhawkins simonjayhawkins deleted the indexes.base branch October 10, 2020 16:05
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants