Skip to content

Add typing annotation to IntervalIndex.intersection #26870

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 5 commits into from
Jun 18, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def overlaps(self, other):

@Appender(_index_shared_docs['intersection'])
@SetopCheck(op_name='intersection')
def intersection(self, other, sort=False):
def intersection(self, other, sort: bool = False):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add typing on other? (and do this for all the intersection calls)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try something as follows in HEAD~1:

    def intersection(self,
                     other: IntervalIndex,
                     sort: bool = False
                     ) -> IntervalIndex:

But this will run into the NameError, i.e.,
NameError: name 'IntervalIndex' is not defined

Copy link
Contributor

Choose a reason for hiding this comment

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

use the string Intervalndex and this will work

if self.left.is_unique and self.right.is_unique:
taken = self._intersection_unique(other)
elif (other.left.is_unique and other.right.is_unique and
Expand Down