Skip to content

Instantly share code, notes, and snippets.

@BryanCutler
Last active May 4, 2021 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BryanCutler/0bac3bd192e458c5be5e6ff31269dce8 to your computer and use it in GitHub Desktop.
Save BryanCutler/0bac3bd192e458c5be5e6ff31269dce8 to your computer and use it in GitHub Desktop.
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