vacanza / holidays

Generate and work with holidays in Python
https://pypi.org/project/holidays
MIT License
1.45k stars 460 forks source link

Object inconsistency #1843

Open ubuntujule opened 3 months ago

ubuntujule commented 3 months ago

after initializing a holiday.[COUNTRY] object and also with holidays.country_holidays('COUNTRY_STRING') the object is a holidays.country_holidays instance object - for example: "<class 'holidays.countries.germany.DE'>"

__repr__ is also "holidays.country_holidays('[COUNTRY')" after initializing but after using a method takes an parameter with a Date (e.g. like Holiday.Base.get_list() method), the __repr__ is a dict with all relevant holidays (which is better than get the class in __repr__ because the class Object we also will get with a type(object) call - in my opinion).

>>>
>>> h = holidays.country_holidays('US')
>>> h
holidays.country_holidays('US')
>>> h.get_list(da)
[]
>>> h
{datetime.date(2024, 1, 1): "New Year's Day", datetime.date(2024, 5, 27): 'Memorial Day', datetime.date(2024, 6, 19): 'Juneteenth National Independence Day', datetime.date(2024, 7, 4): 'Independence Day', datetime.date(2024, 9, 2): 'Labor Day', datetime.date(2024, 11, 11): 'Veterans Day', datetime.date(2024, 11, 28): 'Thanksgiving', datetime.date(2024, 12, 25): 'Christmas Day', datetime.date(2024, 1, 15): 'Martin Luther King Jr. Day', datetime.date(2024, 2, 19): "Washington's Birthday", datetime.date(2024, 10, 14): 'Columbus Day'}
>>>
arkid15r commented 3 months ago

It seems this behavior is intentional. Could you add the expected result as I'm having hard time understanding what's your suggestion for the fix.

I don't expect this to be changed in v0 however I'd be happy to improve this for the next version -- v1 (currently WIP).

Thank you!

ubuntujule commented 3 months ago

I would expect that on first print of the object we also get a dict of all holidays instead of the class.

current output:

>>>
>>> h = holidays.country_holidays('US')
>>> h
holidays.country_holidays('US')
>>> h.get_list(da)
[]
>>> h
{datetime.date(2024, 1, 1): "New Year's Day", datetime.date(2024, 5, 27): 'Memorial Day', datetime.date(2024, 6, 19): 'Juneteenth National Independence Day', datetime.date(2024, 7, 4): 'Independence Day', datetime.date(2024, 9, 2): 'Labor Day', datetime.date(2024, 11, 11): 'Veterans Day', datetime.date(2024, 11, 28): 'Thanksgiving', datetime.date(2024, 12, 25): 'Christmas Day', datetime.date(2024, 1, 15): 'Martin Luther King Jr. Day', datetime.date(2024, 2, 19): "Washington's Birthday", datetime.date(2024, 10, 14): 'Columbus Day'}
>>>

modified output, I would expect:

>>>
>>> h = holidays.country_holidays('US')
>>> h
{datetime.date(2024, 1, 1): "New Year's Day", datetime.date(2024, 5, 27): 'Memorial Day', datetime.date(2024, 6, 19): 'Juneteenth National Independence Day', datetime.date(2024, 7, 4): 'Independence Day', datetime.date(2024, 9, 2): 'Labor Day', datetime.date(2024, 11, 11): 'Veterans Day', datetime.date(2024, 11, 28): 'Thanksgiving', datetime.date(2024, 12, 25): 'Christmas Day', datetime.date(2024, 1, 15): 'Martin Luther King Jr. Day', datetime.date(2024, 2, 19): "Washington's Birthday", datetime.date(2024, 10, 14): 'Columbus Day'}
>>> h.get_list(da)
[]
>>> h
{datetime.date(2024, 1, 1): "New Year's Day", datetime.date(2024, 5, 27): 'Memorial Day', datetime.date(2024, 6, 19): 'Juneteenth National Independence Day', datetime.date(2024, 7, 4): 'Independence Day', datetime.date(2024, 9, 2): 'Labor Day', datetime.date(2024, 11, 11): 'Veterans Day', datetime.date(2024, 11, 28): 'Thanksgiving', datetime.date(2024, 12, 25): 'Christmas Day', datetime.date(2024, 1, 15): 'Martin Luther King Jr. Day', datetime.date(2024, 2, 19): "Washington's Birthday", datetime.date(2024, 10, 14): 'Columbus Day'}
>>>
arkid15r commented 3 months ago

A brand new holidays.country_holidays('US') object is empty be default. You can specify years you want to be populated upon creation using years parameter -- holidays.country_holidays('US', years=2024). Please see the docs for more examples.