-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for more lookup types to pop_named (as in get_named method) #2140
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #2140 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 194 194
Lines 11716 11716
Branches 1771 1771
=========================================
Hits 11716 11716 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @wth-d, thanks for addressing this! I'm really happy this feature request has found its implementer!
I understand it's still in a draft state, just though you'd like some early feedback on how to make your PR better:
@@ -1026,7 +1026,7 @@ def pop(self, key: DateLike, default: Union[str, Any] = None) -> Union[str, Any] | |||
|
|||
return dict.pop(self, self.__keytransform__(key), default) | |||
|
|||
def pop_named(self, name: str) -> list[date]: | |||
def pop_named(self, name: str, lookup: str = "icontains") -> list[date]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the method's documentation with the new param too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the method's docstring
(the part for the lookup param is copied over from docstring of the get_named
method)
@@ -1041,7 +1041,9 @@ def pop_named(self, name: str) -> list[date]: | |||
KeyError if date is not a holiday and default is not given. | |||
""" | |||
use_exact_name = HOLIDAY_NAME_DELIMITER in name | |||
if not (dts := self.get_named(name, split_multiple_names=not use_exact_name)): | |||
if not ( | |||
dts := self.get_named(name, lookup=lookup, split_multiple_names=not use_exact_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be also great to have some tests added too
Hi, thanks for your feedback and for posting this issue. I will try to address your feedback (it may have some delays). |
Hi @wth-d |
Hi, sorry I was busy in the last few weeks. I'm fine with offloading it to the maintainers now. I've also got some draft of tests to add but haven't verified their correctness: def test_contains(self):
self.assertIn("2022-01-01", self.hb)
removed_dates = self.hb.pop_named("Day", lookup="contains")
self.assertEqual(len(removed_dates), 6)
self.assertNotIn("2022-01-01", self.hb)
self.assertNotIn("2022-06-19", self.hb)
self.assertNotIn("2022-06-20", self.hb)
self.assertNotIn("2022-07-04", self.hb)
self.assertNotIn("2022-12-25", self.hb)
self.assertNotIn("2022-12-26", self.hb)
def test_exact(self):
self.assertIn("2022-01-01", self.hb)
removed_dates = self.hb.pop_named("Presidents' Day", lookup="exact")
self.assertEqual(len(removed_dates), 1)
self.assertNotIn("2022-02-21", self.hb)
def test_icontains(self):
self.assertIn("2022-01-01", self.hb)
removed_dates = self.hb.pop_named("day", lookup="icontains")
self.assertEqual(len(removed_dates), 6)
self.assertNotIn("2022-01-01", self.hb)
self.assertNotIn("2022-06-19", self.hb)
self.assertNotIn("2022-06-20", self.hb)
self.assertNotIn("2022-07-04", self.hb)
self.assertNotIn("2022-12-25", self.hb)
self.assertNotIn("2022-12-26", self.hb) A strange thing was that when I executed
but when I executed it in the tests/test_holiday_base.py file (using
|
self.hb is special |
Proposed change
Adds the
lookup
parameter to thepop_named
methodAddresses issue #2137
Type of change
holidays
functionality in general)Checklist
make check
, all checks and tests are green