From 46039397379a812c610e974c1c336ba580c444d3 Mon Sep 17 00:00:00 2001 From: wth-d <111629334+wth-d@users.noreply.github.com> Date: Tue, 26 Nov 2024 01:29:51 -0500 Subject: [PATCH 1/2] Add support for more lookup types to pop_named (as in get_named method) --- holidays/holiday_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 70d8b80ea..7b773e390 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -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]: """Remove (no longer treat at as holiday) all dates matching the provided holiday name. The match will be made case insensitively and partial matches will be removed. @@ -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) + ): raise KeyError(name) popped = [] From a0a855d34c2c31e341bf883c6ddfd3b94a834cf3 Mon Sep 17 00:00:00 2001 From: wth-d <111629334+wth-d@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:15:32 -0500 Subject: [PATCH 2/2] Modify the docstring of the pop_named method --- holidays/holiday_base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/holidays/holiday_base.py b/holidays/holiday_base.py index 7b773e390..32633026e 100644 --- a/holidays/holiday_base.py +++ b/holidays/holiday_base.py @@ -1028,11 +1028,19 @@ def pop(self, key: DateLike, default: Union[str, Any] = None) -> Union[str, Any] def pop_named(self, name: str, lookup: str = "icontains") -> list[date]: """Remove (no longer treat at as holiday) all dates matching the - provided holiday name. The match will be made case insensitively and + provided holiday name. By default, the match will be made case insensitively and partial matches will be removed. :param name: The holiday's name to try to match. + :param lookup: + The holiday name lookup type: + contains - case sensitive contains match; + exact - case sensitive exact match; + startswith - case sensitive starts with match; + icontains - case insensitive contains match; + iexact - case insensitive exact match; + istartswith - case insensitive starts with match; :return: A list of dates removed.