-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Initial implementation of holiday and holiday calendar. #6719
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
Implementation of holidays and holiday calendars to be used with the CustomBusinessDay offset. Also add an Easter holiday for use in calendars.
class USFederalHolidayCalendar(AbstractHolidayCalendar): | ||
|
||
_rule_table = [ | ||
Holiday('New Years Day', month=1, day=1, observance=Nearest), |
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.
Why not factor all holidays out as constants like Memorial Day, etc so that they can be re-used by other HolidayCalendars?
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.
I did it for the holidays that shouldn't change observances. If you look at my two calendars I put there, the other holidays have different observances. There could be a default set, but I think caution needs to be taken when doing these types of holidays.
Can you add a new section after this one on how to use holidays? And in v0.14.0.txt (you can make a subsection if you need or just a bullet) http://pandas.pydata.org/pandas-docs/stable/timeseries.html#dateoffset-objects and then include a short example in the top of this PR. |
Implementation of holidays and holiday calendars to be used with the CustomBusinessDay offset. Also add an Easter holiday for use in calendars.
@jreback sections and examples added. |
@rockg a couple of suggestions / comments
|
USMemorialDay, | ||
Holiday('July 4th', month=7, day=4, observance=Nearest), | ||
Holiday('Columbus Day', month=10, day=1, | ||
offset=DateOffset(weekday=MO(2))), |
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.
I think this offset can be Week(weekday='Monday')
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.
Needs to be Week(weekday=0) or some other integer. I think the example is illustrative enough. I'll put a comment pointing this alternative out.
@jreback changes incorporated.
|
Let's say you want to represent the NYSE holiday calendar which has full market closures and half days.how should that be represented with this? |
I think it depends on the type of holiday (fixed date--July 4th--versus floating date--Memorial Day). I think fixed date half days belong in the observance rule, but floating date half days belong in the offset. For example, the Friday after Thanksgiving would be an offset
or it can just be in July 4th's observance rule to return a list of dates. Some changes would need to happen to accept None or a list return from an observance rule, but these are trivial. To me the time would be the best way to represent such a thing unless you added an indicator and returned a Series/DataFrame with such information but that seems overkill. I'm assuming this would just be in timeseries analysis as I don't believe CustomBusinessDays can handle half days and I don't know what that means in a daily context. |
@jreback where should the default dates go for the holiday range in AbstractHolidayCalendar.holidays? A configuration file or somewhere else? |
@rockg I think they can stay in the main file, they are pretty common (though maybe take out the NERC one....). The user will almost certainly override / replace with their own. and just register it. In fact I think pandas should maybe not define ANY calendars (but it makes a nice easy example), so USFederalHolidays is fine. We don't really have a config file anywhere, so would be tricky. |
here's some rules that I use (some might be worthwhile to incorporate). also pls use lowercase for the rules (they are functions) |
What I was referring to for default dates was the below. This seems wrong to me and seems like it should live in a configuration file or something similar.
|
I would just set those as class variables on the Abstract class, they can always be overriden (you could also create some options for this, ala |
I don't think that you should actually pre-generate this, maybe instead cache the generation on demand (a bit harder to track), but I think better |
I don't believe anything is pre-generated (I assume you are referring to holidays()). I wanted to add caching, but I figured there was already a mechanism in pandas (would need a pointer) or I can just add my own memoization. |
date caching is really tricky, but you can look in just cache in the class |
@jreback I'm confused about your previous_friday_full function. It's not doing what I expect based on the comment:
|
yeh...this is a weird one, only used for japan holidays. has to so with my concept of full/half days, e.g. certain days the market can be open (at the beginning of the year), but they don't count for holiday purposes (very weird). would just take that one out....i just copied all of my defs... |
Implementation of holidays and holiday calendars to be used with the CustomBusinessDay offset. Also add an Easter holiday for use in calendars.
@jreback Think we are there. Please take a look (Travis failures are only TestYahoo). |
return 'Holiday: %s (%s)' % (self.name, info) | ||
|
||
def dates(self, start_date, end_date, return_name=False): | ||
''' |
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.
I think you need a coercion step, here start_date = Timestamp(start_date)
, (and some tests, as I think a string/datetime/timestamp could be passed)
…dd additional tests for functionality. Also, add release note.
@jreback Maybe now it's okay? |
yes...looks good...pls rebase and squash down a bit if you can ping me when green |
All right, need some git help. When I try to squash everything together I get the below. Only answers I see talk about conflicts, but I have none that I know of. What determines whether a commit can be squashed or not? error: could not apply f37742e... Convert map object to list for python 3. When you have resolved this problem run "git rebase --continue". Could not apply f37742e... Convert map object to list for python 3. |
Conflicts occur when incoming commit has one or more modifications that overlap your own, git refuses to choose how to combine those changes and lets you do that for him. Git will put all non-overlapping changes to staging area and the rest will remain in the working directory wrapped in markup to stand out. If you do |
@rockg I rebased and squashed...here it is if it looks ok...can merge... Can always do a follow up PR for fixes/corrections. |
@jreback, that looks great as far as I can tell. How did you do it? |
not sure exactly how you got in this state my workflow is to do a commit did you do any merges or anything? |
merged via 8e3bdfe thanks! check out docs when they are built (should be shortly) |
What you did makes sense, but that wasn't working. I have no idea how I got in that state. I did have some issues with some commits...conflicts and things that I wasn't expecting and maybe in resolving those I created the issues. Nevertheless, thank you. The hardest part about all this was making git do what I want (maybe 50% of the time) which doesn't seem like it should be the case. |
git is a beast at times. here is a sample of @cpcloud workflow https://github.com/pydata/pandas/wiki/Git-Workflows not entirely sure how you go in that state...no biggie though... |
docs are out Can you do a follow up PR I would change the in-line comments (the pound sign), to put above the comment (easier to read). also can you show an example of actually using the ExampleCalendar, e.g. by defining a CustomBusinessDay index and say adding offsets, to show how it skips weekends and holidays. thanks |
@rockg I see you do have an example where you are adding the custom biz day, but maybe make it a tad longer |
Implementation of holidays based on DateOffset objects and calendars that are collections of those holidays. These calendars can be passed into CustomBusinessDay. Also, add an Easter offset for use in holiday calendars.
Currently the default dates are hard-coded in the calendar class but this should move somewhere else and be calculated differently. I'm open to suggestions here. Also, the 4-day weekend observance needs to be incorporated (for example, if July 4th is on a Tuesday, perhaps Monday is also a holiday). This would require a little bit of tweaking, but not much.