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 3 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
13 changes: 10 additions & 3 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,10 @@ def overlaps(self, other):

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

Choose a reason for hiding this comment

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

typing nitpick, we use single quotes on these annotations, otherwise lgtm. ping on green.

@WillAyd can we systematically check this?

other: "IntervalIndex",
sort: bool = False
) -> "IntervalIndex":
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 All @@ -1157,7 +1160,9 @@ def intersection(self, other, sort=False):

return taken

def _intersection_unique(self, other):
def _intersection_unique(self,
other: "IntervalIndex"
) -> "IntervalIndex":
"""
Used when the IntervalIndex does not have any common endpoint,
no mater left or right.
Expand All @@ -1179,7 +1184,9 @@ def _intersection_unique(self, other):

return self.take(indexer)

def _intersection_non_unique(self, other):
def _intersection_non_unique(self,
other: "IntervalIndex"
) -> "IntervalIndex":
"""
Used when the IntervalIndex does have some common endpoints,
on either sides.
Expand Down