Last active
May 4, 2021 22:53
-
-
Save BryanCutler/0bac3bd192e458c5be5e6ff31269dce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SpanOpMixin: | |
def __add__(self, other) -> Union["Span", "SpanArray"]: | |
if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)): | |
# Rely on pandas to unbox and dispatch to us. | |
return NotImplemented | |
if isinstance(self, Span) and isinstance(other, Span): | |
# Span + *Span = Span | |
return Span(self.target_text, | |
min(self.begin, other.begin), | |
max(self.end, other.end)) | |
# SpanArray + *Span* = SpanArray | |
return SpanArray(self.target_text, | |
np.minimum(self.begin, other.begin), | |
np.maximum(self.end, other.end)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment