- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 560
          Update HolidayBase::pop_named: add support for more lookup types
          #2140
        
          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
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          204       204           
  Lines        12999     13012   +13     
  Branches      1861      1866    +5     
=========================================
+ Hits         12999     13012   +13     ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
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:
| 
 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  | 
| We need to add handling of all  | 
| And in the case when we delete one holiday from multiple holidays date, should the method return this date? | 
| 
 I think yes as long as there is another holiday on the same date. | 
| But according to documentation, it returns list of dates removed. And this date has not been removed because there is still a holiday. | 
| 
 Right, I forgot we talk about  | 
HolidayBase::pop_named: add support for more lookup types
      | I decide to bring this good idea to completion. When deleting one holiday from multiple holidays date, this date will be present in function result (i.e., function behavior has not changed). | 
| Summary by CodeRabbit
 WalkthroughThe changes update the  Changes
 ✨ Finishing Touches
 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
 Other keywords and placeholders
 Documentation and Community
 | 
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.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
- holidays/holiday_base.py(2 hunks)
- tests/test_holiday_base.py(1 hunks)
🔇 Additional comments (9)
holidays/holiday_base.py (3)
1083-1086: Method signature updated to improve flexibility for holiday lookups.The change from
nametoholiday_nameparameter makes the intended purpose clearer, and adding thelookupparameter with a default value of "icontains" maintains backward compatibility while adding new functionality.
1088-1098: Documentation updated properly to include the new parameter.The docstring has been updated to clearly document the new
lookupparameter and its supported values. This matches the existing style and level of detail in other method docstrings.
1105-1112: Good use ofget_namedto avoid duplicating lookup logic.Reusing the underlying
get_namedmethod's functionality ensures consistent behavior between getting and popping named holidays.tests/test_holiday_base.py (6)
842-852: Good test for the 'contains' lookup.The test verifies that holidays containing "Day" are correctly removed while maintaining the integrity of the holidays dictionary.
853-863: Good test for the 'icontains' lookup.This test confirms case-insensitive contains functionality works as expected, correctly removing the same holidays as the case-sensitive version when using a lowercase pattern.
864-878: Excellent test for the 'exact' lookup that verifies multiple holiday handling.This test checks both basic exact matching and the more complex case of multiple holidays on the same date, ensuring only the exact matched holiday is removed.
879-893: Good test for the 'iexact' lookup.The test correctly verifies case-insensitive exact matching behavior, including the case with multiple holidays on the same date.
894-906: Thorough test for the 'startswith' lookup.The test checks both single and multiple date removal scenarios, ensuring the correct behavior when removing holidays that start with the specified pattern.
907-919: Good test coverage for the 'istartswith' lookup.The test verifies case-insensitive prefix matching works correctly for both single and multiple dates.
# Conflicts: # holidays/holiday_base.py
| 
 | 
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
- holidays/holiday_base.py(2 hunks)
🔇 Additional comments (2)
holidays/holiday_base.py (2)
1175-1194: Clear and comprehensive docstring for the newpop_namedmethod
Your explanation of the newly introducedlookupparameter and its usage is thorough and aligns well with the existingget_namedmethod. The mention of case sensitivity and partial matching options helps readers understand how holidays will be removed.
1217-1245: Duplicate filtering logic for different lookup types
This block mirrors the approach used inget_named, duplicating the filtering pattern for each lookup variant. Consider extracting a helper function (e.g.,_filter_holiday_names) to maintain consistency and reduce duplication across the codebase.
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.
LGTM
| AFAIK this PR already got updated with Sphinx -> MkDocs migration, so it should be more or less ready | 
| 
 It's next in my queue for review | 
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.
@wth-d @KJhellico thanks for adding this!



Proposed change
Adds the
lookupparameter to thepop_namedmethodAddresses issue #2137
Type of change
holidaysfunctionality in general)Checklist
make check, all checks and tests are green