-
Notifications
You must be signed in to change notification settings - Fork 470
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
Holiday categories: inconsistent behaviour and ghost categories 🌫️ #1559
Comments
Hi, @tpvasconcelos! Thank you for a very clear and detailed issue description!
Yes, we will most likely do that. 👍
Exactly! Fixed in #1562.
This is how it should be everywhere. Brazil was simply "lost". 🙂 |
Hi @tpvasconcelos, thanks for posting this! The PH categories support is quite recent addition to the library and is still WIP. I appreciate the meaningful feedback you've provided. This will definitely help us improve the end-user experience. It has already been addressed partially in today's v0.37 release (#1562 by @KJhellico) and I expect the rest to be sorted out in v0.38. |
Thanks for the quick responses @arkid15r and @KJhellico! This behaviour can also be seen with holiday subdivisions. However, in this case, I guess that the default behaviour does make sense. i.e., holidays with no explicit subdivision should implicitly apply to all country subdivisions. That said, I still think that this behaviour does not make sense for categories. If you agree that Option 1 (explicit)The explicit approach would be to not allow adding categoryless holidays, forcing the user to explicit mark them as For instance, this line would be removed: The all instances of A big downside of this approach is that it introduces a big regression and will likely break lots of user code. If this route is considered, them maybe an initial step towards this would be to add a deprecation warning to Option 2 (implicit)This option avoids breaking lots of user code but would probably warrant careful documentation of the behaviours making it very clear that to: method_names = []
if PUBLIC in self.categories:
method_names.append(f"_add_subdiv_{subdiv}_holidays")
for category in sorted(self.categories):
method_names.append(f"_add_subdiv_{subdiv}_{category}_holidays") If you wish, I would be happy to help out 👍 |
That's exactly what we planned - PUBLIC as category supported by default. And over time, all countries will switch to this format (with
They are the internal methods of |
Do you mean that users should only interact with |
It would be great to support the creation of arbitrary holidays. This might be a new issue altogether but it doesn't seem like it would be hard to implement. Take, for instance, the example where you want to create a custom holiday class for your company's holidays: class MyCompanyHolidays(holidays.HolidayBase):
supported_categories = {"ALL", "CONTRACT", "EXTERNAL"}
subdivisions = ("EMEA", "APLA", "NA")
# For everyone in EMEA
def _add_subdiv_emea_all_holidays(self):
self._add_holiday_jan_1("New Year")
# Only for full-time employees in North America
def _add_subdiv_na_contract_holidays(self):
self._add_holiday_feb_2("Mental health day")
# This should fail instead of defaulting to PUBLIC
def _add_subdiv_apla_holidays(self):
self._add_holiday_mar_3("A holiday for everyone in APLA")
# For all external workers (across all subdivisions)
def _populate_external_holidays(self):
self._add_holiday_jul_4("Forced time off") I believe that the only thing in the way of allowing a user to create this is again the |
Hi @tpvasconcelos, it's great to have such a detailed and valuable feedback from time to time. We've created several PRs and significantly improved the code quality based on your ideas. Taking into account your interest I'd like to mention that this year our goal is to release v1 of the library. We could definitely use suggestions on what features would be useful to implement from users' perspective. Any input is appreciated! |
Hey
holiday
folks!While exploring this package, I came across a few unexpected and inconsistent behaviours regarding holiday categories. I hope you can shed some light on where I'm going wrong.
Strange behaviour 1
While all entities can declare a set of
supported_categories
, this is never validated, enforced, or otherwise used anywhere else in the codebase.For instance, should this not be checked here:
https://github.com/vacanza/python-holidays/blob/daa4b804a342368b21477636f7c04ca7d86088aa/holidays/holiday_base.py#L320-L324
e.g.,
Strange behaviour 2
The
categories
field has to be a tuple but when left empty defaults to the{PUBLIC}
set. On the other hand, thesupported_categories
attribute is an empty set by default. So, by default, you always queryPUBLIC
holidays from an entity with no supported categories.Should this be standardized such that both
categories
andsupported_categories
are sets (or justiterables
) and both default to{PUBLIC}
(such that, by default, all entities supportPUBLIC
holidays)?Strange behaviour 3.1
Sometimes... you can query unsupported categories from entities that do specify
supported_categories
I believe this happens because of the logic defined in the base
_add_subdiv_holidays()
method which tries to register_add_subdiv_to_islamic_holidays()
(doesn't register anything in this case) and_add_subdiv_to_holidays()
which is called no matter the values thecategories
tuple.I'm not sure what the solution should be here but it looks like
_add_subdiv_{subdiv}_holidays
should default to_add_subdiv_{subdiv}_public_holidays
to respect the category filters. I believe this would also be consistent with my suggestion in "Strange behaviour 2".This becomes even more unintuitive when the user gets different results for different categories:
which would lead the user to believe that these 3 holidays were
islamic
but they are in-fact "categoryless" or "pan-categorical" since they always get returned no matter the categories passedStrange behaviour 3.2
Other times... you can only query categories that are defined in
supported_categories
.Which happens because Portugal explicitly marks all holidays as either OPTIONAL or PUBLIC (i.e., there are no "categoryless" holidays).
https://github.com/vacanza/python-holidays/blob/daa4b804a342368b21477636f7c04ca7d86088aa/holidays/countries/portugal.py#L194-L208
Possible solutions
In order to make the category filtering behaviour more intuitive and internally consistent, I can only think of the following two options:
category=None
should be used for this special case.Ideally, this snippet would work exactly the same if the user set
categories = holidays.ALL_CATEGORIES
.👆 Alternatively, you could also raise a
ValueError
for unsupported categories as suggested in "Strange behaviour 1".Sorry for the long post... I hope this helps :)
The text was updated successfully, but these errors were encountered: