__init__.py

About this file

This file contains the NYCHolidays class, extended from the HolidayBase class. When calling the _populate method, observed holidays are added to its list of holidays, such as Labor Day and Thanksgiving.

'holidays library' is used to determine whether a specific date is holiday or not in a particular country.
Each country has two class names - an abbreviation and a full name. Some holidays can be states specific as well.

'observed' param: (Default: True)
January 1st, 2012 fell on a Sunday so the statutory holiday was observed on the 2nd.
Therefore, January 2nd, 2012 gets included in the holiday list of that year.

>>> us_holidays.get(date(2012 ,1, 2))
"New Year's Eve (Observed)"

'expand' param: (Default: True)
It is a boolean value specifying whether or not to append holidays in new years to the holidays object.
This is set to False in function '_populate' meaning the Holiday object will no longer add holidays from new years.
So, the function adds Dec 31st from the previous year without triggering the entire year to be added.

The file also checks the year since when the respective holidays are celebrated.
Example:
New Year's Day since 1870, Columbus Day since 1970

Code Issues

  • Needs a comment specifying how the class is used for the application
  • Lines 22-25 looks confusing since expand is used to replace self.expand's value of False, which doesn't appear to be used.
        
        expand = self.expand
        self.expand = False
        self[date(year, 1, 1) + rd(days=-1)] = name + " (Observed)"
        self.expand = expand
        
      
    Needs comments explaining what self.expand does - what does True and False mean for this attribute?

Code Check Report


No problems to report
                        

Documentation drawn from source code


NYCHolidays(HolidayBase):

__init__(self, **kwargs):

_populate(self, year):

Source code