Skip to content

Conversation

@wth-d
Copy link
Contributor

@wth-d wth-d commented Nov 26, 2024

Proposed change

Adds the lookup parameter to the pop_named method
Addresses issue #2137

Type of change

  • New country/market holidays support (thank you!)
  • Supported country/market holidays update (calendar discrepancy fix, localization)
  • Existing code/documentation/test/process quality improvement (best practice, cleanup, refactoring, optimization)
  • Dependency update (version deprecation/pin/upgrade)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (a code change causing existing functionality to break)
  • New feature (new holidays functionality in general)

Checklist

@codecov
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5e9f05a) to head (5f72812).
Report is 10 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@arkid15r arkid15r left a 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:

@wth-d
Copy link
Contributor Author

wth-d commented Nov 27, 2024

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).

@arkid15r
Copy link
Collaborator

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
Any progress w/ pop_named tests? Are you still interested in working on it or don't mind to offload it to the maintainers :) ?

@wth-d
Copy link
Contributor Author

wth-d commented Dec 28, 2024

Hi @wth-d Any progress w/ pop_named tests? Are you still interested in working on it or don't mind to offload it to the maintainers :) ?

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 h.get_named("Day", lookup="contains", split_multiple_names=False) using the holidays library installed from pip, I got this as the result:

h = holidays.country_holidays('US')

[datetime.date(2022, 1, 1), datetime.date(2022, 5, 30), datetime.date(2022, 6, 19), 
datetime.date(2022, 6, 20), datetime.date(2022, 7, 4), datetime.date(2022, 9, 5), 
datetime.date(2022, 11, 11), datetime.date(2022, 12, 25), datetime.date(2022, 12, 26), 
datetime.date(2022, 1, 17)]

but when I executed it in the tests/test_holiday_base.py file (using self.hb instead of h), I got this:

[datetime.date(2022, 1, 1), datetime.date(2022, 6, 19), datetime.date(2022, 6, 20), 
datetime.date(2022, 7, 4), datetime.date(2022, 12, 25), datetime.date(2022, 12, 26)]

@KJhellico
Copy link
Collaborator

but when I executed it in the tests/test_holiday_base.py file (using self.hb instead of h), I got this:

self.hb is special CountryStub1 class, and it doesn't contain a full set of US holidays.

@KJhellico
Copy link
Collaborator

KJhellico commented Feb 8, 2025

We need to add handling of all lookup variants here, similar to get_named().

@KJhellico
Copy link
Collaborator

And in the case when we delete one holiday from multiple holidays date, should the method return this date?

@arkid15r
Copy link
Collaborator

arkid15r commented Feb 9, 2025

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.

@KJhellico
Copy link
Collaborator

But according to documentation, it returns list of dates removed. And this date has not been removed because there is still a holiday.

@arkid15r
Copy link
Collaborator

arkid15r commented Feb 9, 2025

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 pop_named not get_named. This is something we need think through in order to minimize confusion from end users perspective.

@github-actions github-actions bot added the test label Feb 27, 2025
@KJhellico KJhellico changed the title Add support for more lookup types to pop_named (as in get_named method) Update HolidayBase::pop_named: add support for more lookup types Feb 27, 2025
@KJhellico
Copy link
Collaborator

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).

@KJhellico KJhellico marked this pull request as ready for review February 27, 2025 21:44
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the holiday removal functionality by allowing users to specify flexible matching criteria, such as exact, partial, and case-sensitive or case-insensitive options.
  • Tests

    • Expanded testing to validate multiple lookup strategies, ensuring that the updated holiday removal behaves as expected under various conditions.

Walkthrough

The changes update the pop_named method in the HolidayBase class by modifying its signature to accept a new holiday_name parameter and an optional lookup parameter, which allows for different matching strategies. The method logic, associated docstring, and exception handling were adjusted accordingly. Additionally, several new tests were added to verify the method's behavior using various lookup strategies such as exact, contains, and their case-sensitive variants.

Changes

File Change Summary
holidays/…/holiday_base.py Updated the pop_named method: changed the signature to accept holiday_name and lookup (default "icontains"), updated the docstring and logic for flexible lookup criteria, and refined exception handling.
tests/…/test_holiday_base.py Added new test methods (test_contains, test_icontains, test_exact, test_iexact, test_startswith, test_istartswith) to validate the pop_named method with various lookup strategies.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f52858 and d44329e.

📒 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 name to holiday_name parameter makes the intended purpose clearer, and adding the lookup parameter 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 lookup parameter and its supported values. This matches the existing style and level of detail in other method docstrings.


1105-1112: Good use of get_named to avoid duplicating lookup logic.

Reusing the underlying get_named method'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.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 85e56a9 and 5f72812.

📒 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 new pop_named method
Your explanation of the newly introduced lookup parameter and its usage is thorough and aligns well with the existing get_named method. 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 in get_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.

@KJhellico KJhellico requested a review from arkid15r March 27, 2025 21:16
Copy link
Collaborator

@PPsyrius PPsyrius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PPsyrius
Copy link
Collaborator

PPsyrius commented Apr 1, 2025

AFAIK this PR already got updated with Sphinx -> MkDocs migration, so it should be more or less ready

@arkid15r
Copy link
Collaborator

arkid15r commented Apr 1, 2025

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

Copy link
Collaborator

@arkid15r arkid15r left a 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!

@arkid15r arkid15r enabled auto-merge April 1, 2025 23:01
@arkid15r arkid15r added this pull request to the merge queue Apr 1, 2025
Merged via the queue into vacanza:dev with commit b870ccf Apr 1, 2025
33 checks passed
@arkid15r arkid15r mentioned this pull request Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend HolidayBase::pop_named to support HolidayBase::get_named lookup param

4 participants