Skip to content

Commit 8cfa8f0

Browse files
committed
Refine eq and contains checks for unknown and partial unknowns
1 parent 34b6688 commit 8cfa8f0

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/undate/undate.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,9 @@ def __contains__(self, other: "Undate") -> bool:
247247
return (
248248
self.earliest <= other.earliest
249249
and self.latest >= other.latest
250-
# precision is not sufficient for comparing partially known dates
250+
# is precision sufficient for comparing partially known dates?
251251
and self.precision > other.precision
252252
)
253-
# TODO: how to compare partially unknown values
254-
# like 19xx and 199x or 1801-XX and 1801-1X
255253

256254
@property
257255
def known_year(self) -> bool:

tests/test_undate.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def test_lt_notimplemented(self):
214214
(Undate(2022, 1, 1), Undate(2022)),
215215
(Undate(2022, 12, 31), Undate(2022)),
216216
(Undate(2022, 6, 15), Undate(2022, 6)),
217-
# TODO: support partially known dates that are unambiguously in range
218-
# (Undate("199X"), Undate("19XX")),
219217
]
220218

221219
@pytest.mark.parametrize("date1,date2", testdata_contains)
@@ -227,26 +225,23 @@ def test_contains(self, date1, date2):
227225
(Undate(1980), Undate(2020)),
228226
(Undate(1980), Undate(2020, 6)),
229227
(Undate(1980, 6), Undate(2020, 6)),
228+
# partially known dates that are similar but same precision,
229+
# so one does not contain the other
230+
(Undate("199X"), Undate("19XX")),
231+
# - specific month to unknown month
232+
(Undate(1980, 6), Undate(1980, "XX")),
233+
# some of these might overlap, but we don't have enough
234+
# information to determine
235+
# - unknown month to unknown month
236+
(Undate(1980, "XX"), Undate(1980, "XX")),
237+
# - partially unknown month to unknown month
238+
(Undate(1801, "1X"), Undate(1801, "XX")),
230239
]
231240

232241
@pytest.mark.parametrize("date1,date2", testdata_not_contains)
233242
def test_not_contains(self, date1, date2):
234243
assert date1 not in date2
235244

236-
def test_contains_ambiguous(self):
237-
# date not in range due to precision
238-
# TODO: can we return an unknown instead of false?
239-
# or should this raise a not implemented error?
240-
241-
# these are cases where dates *might* overlap,
242-
# but we don't have enough information to determine
243-
# - specific month to unknown month
244-
assert Undate(1980, 6) not in Undate(1980, "XX")
245-
# - unknown month to unknown month
246-
assert Undate(1980, "XX") not in Undate(1980, "XX")
247-
assert Undate(1980, 6) not in Undate(1980, "XX")
248-
assert Undate(1801, "1X") not in Undate(1801, "XX")
249-
250245
def test_sorting(self):
251246
# sorting should be possible based on gt/lt
252247
# test simple cases for sorting

0 commit comments

Comments
 (0)