Skip to content

Commit cfdef42

Browse files
committed
Revise contains logic: interval contains itself or equivalent interval
1 parent 700c834 commit cfdef42

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/undate/interval.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ def duration(self) -> Timedelta:
125125

126126
def __contains__(self, other: object) -> bool:
127127
"""Determine if another interval or date falls within this
128-
interval."""
129-
# support comparison with another interval
128+
interval. Supports comparison with :class:`UndateInterval`
129+
or anything that can be converted with :meth:`Undate.to_undate`."""
130+
# support comparison with another interval or anything
131+
# that can be converted to an Undate
130132
if isinstance(other, UndateInterval):
131-
# if two intervals are strictly equal, don't consider
132-
# either one as containing the other
133-
if self == other:
134-
return False
135-
# otherwise compare based on earliest/latest bounds
133+
# compare based on earliest/latest bounds
136134
other_earliest = other.earliest
137135
other_latest = other.latest
138136
else:

tests/test_interval.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def test_contains(self):
186186
century11th = UndateInterval(Undate(1001), Undate(1100))
187187
century20th = UndateInterval(Undate(1901), Undate(2000))
188188
decade1990s = UndateInterval(Undate(1990), Undate(1999))
189-
# an interval doesn't contain itself
189+
# an interval DOES contain itself
190190
for interval in [century11th, century20th, decade1990s]:
191-
assert interval not in interval
191+
assert interval in interval
192192

193193
# checking if an interval is within another interval
194194
assert decade1990s in century20th
@@ -228,4 +228,6 @@ def test_contains(self):
228228
# fully open interval - is this even meaningful?
229229
whenever = UndateInterval(None, None)
230230
assert decade1990s in whenever
231-
assert whenever not in whenever
231+
# NOTE: an interval contains itself or an equivalent interval,
232+
# but that may not make sense for open intervals...
233+
assert whenever in whenever

0 commit comments

Comments
 (0)