MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / union

Method union

lib/sqlalchemy/dialects/postgresql/ranges.py:499–543  ·  view source on GitHub ↗

Compute the union of this range with the `other`. This raises a ``ValueError`` exception if the two ranges are "disjunct", that is neither adjacent nor overlapping.

(self, other: Range[_T])

Source from the content-addressed store, hash-verified

497 )
498
499 def union(self, other: Range[_T]) -> Range[_T]:
500 """Compute the union of this range with the `other`.
501
502 This raises a ``ValueError`` exception if the two ranges are
503 "disjunct", that is neither adjacent nor overlapping.
504 """
505
506 # Empty ranges are "additive identities"
507 if self.empty:
508 return other
509 if other.empty:
510 return self
511
512 if not self.overlaps(other) and not self.adjacent_to(other):
513 raise ValueError(
514 "Adding non-overlapping and non-adjacent"
515 " ranges is not implemented"
516 )
517
518 slower = self.lower
519 slower_b = self.bounds[0]
520 supper = self.upper
521 supper_b = self.bounds[1]
522 olower = other.lower
523 olower_b = other.bounds[0]
524 oupper = other.upper
525 oupper_b = other.bounds[1]
526
527 if self._compare_edges(slower, slower_b, olower, olower_b) < 0:
528 rlower = slower
529 rlower_b = slower_b
530 else:
531 rlower = olower
532 rlower_b = olower_b
533
534 if self._compare_edges(supper, supper_b, oupper, oupper_b) > 0:
535 rupper = supper
536 rupper_b = supper_b
537 else:
538 rupper = oupper
539 rupper_b = oupper_b
540
541 return Range(
542 rlower, rupper, bounds=cast(_BoundsType, rlower_b + rupper_b)
543 )
544
545 def __add__(self, other: Range[_T]) -> Range[_T]:
546 return self.union(other)

Callers 10

__add__Method · 0.95
__new__Method · 0.45
PGDialectClass · 0.45
MSDialectClass · 0.45
in_boolean_modeMethod · 0.45
with_query_expansionMethod · 0.45
reserved_words.pyFile · 0.45

Calls 5

overlapsMethod · 0.95
adjacent_toMethod · 0.95
_compare_edgesMethod · 0.95
RangeClass · 0.85
castFunction · 0.50

Tested by

no test coverage detected