Skip to content

TYP: annotations in indexes #31181

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

Merged
merged 24 commits into from
Jan 24, 2020
Merged

TYP: annotations in indexes #31181

merged 24 commits into from
Jan 24, 2020

Conversation

jbrockmendel
Copy link
Member

No description provided.

@pep8speaks
Copy link

pep8speaks commented Jan 21, 2020

Hello @jbrockmendel! 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 2020-01-22 19:29:15 UTC

@@ -632,6 +637,10 @@ def shape(self):
"""
return self._values.shape

def __len__(self) -> int:
Copy link
Member

Choose a reason for hiding this comment

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

What error was this throwing? Slightly hesitant to do something like this as it could interfere with Mixins that define this otherwise

Copy link
Member Author

Choose a reason for hiding this comment

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

pandas/core/base.py:1343: error: Argument 1 to "len" has incompatible type "IndexOpsMixin"; expected "Sized"

Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to just ignore that line; I think mypy generally doesn't play nice with Mixins so may be a few things like this, but I would imagine the intent is for that to be defined by whatever gets composed with this class

Not a big deal for me either way maybe just a note for other reviewers. Otherwise this lgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

@simonjayhawkins thoughts here?

Copy link
Member

Choose a reason for hiding this comment

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

perhaps for consistency with addition for _values above, __len__ could raise AbstractMethodError instead?

another alternative could be to add a type declaration at the top of the class instead,
__len__: Callable[..., int]

or ignore as @WillAyd suggested.

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Jan 22, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Jan 22, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@jbrockmendel generally lgtm. some comments but could be follow-on if appropriate.

@property
def is_monotonic_increasing(self) -> bool:
"""alias for is_monotonic"""
# mypy complains if we alias directly
Copy link
Member

Choose a reason for hiding this comment

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

probably don't need the comment.

In Index, is_monotonic is an alias for is_monotonic_increasing, whereas here is_monotonic_increasing is an alias for is_monotonic. Would it make sense to make these consistent instead?

Although without going deeper, looks strange that is_monotonic returns Index(self).is_monotonic, maybe the code there, should be here.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe the code there, should be here.

it does seem a little weird, but its because this gets mixed in to Series, so Series.is_monotonic needs to wrap in Index so that it can use IndexEngine

if self.inferred_type == "string":
is_justify = False
elif self.inferred_type == "categorical":
if is_object_dtype(self.categories): # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

the error here is pandas\core\indexes\base.py:910: error: "Index" has no attribute "categories". should this special case be in CategoricalIndex instead of in the base Index class?

@jreback jreback merged commit e5227c4 into pandas-dev:master Jan 24, 2020
@jreback
Copy link
Contributor

jreback commented Jan 24, 2020

thanks!

@jbrockmendel jbrockmendel deleted the cln-idx branch January 24, 2020 04:42
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.

5 participants