-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: seems that subtracting a YearBegin offset from an index loses the months/days #4804
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
Comments
I agree this is a bug. It seems to me something is going on with the timezones. When you just look at df.index - pd.offsets.YearBegin(1) (not the values) you get the right times. If you provide a timezone initially as US/Eastern, the times you expect are returned. Also, I believe there is a bug in dateutil which doesn't observe the timezone information and so all resulting times are shifted by offset of the initial date rather than the resulting date. For example, taking a March dst time and shifting to the beginning of the month, retains the dst offset of the start date (so you actually get the last hour of February returned).
The last time should be 19:00:00 DST |
Actually I think this is just a representation issue of datetime64 that casts the time as local to what seems to be the machine's timezone. I cannot find the code where this happens, though. Case in point:
|
If I set my machine's TZ to UTC and do the above. I get the following: index = date_range('20140101 00:15:00',freq='D',periods=10) So I'm confident that it is just a display issue. |
@rockg so there is not easy way to effectily just subtract a year? Like a 'fixed' year, one that does not reset to the begin/end of year? (month obviously cannot support this as that can cause a month/year roll), but seems we need a:
|
@jreback -- sorry, I was misunderstanding your statement (I thought you were commenting on the seemingly incorrect days/hours when using YearBegin). I agree that a Year offset is basic functionality. A couple more would be useful as well--WeekendDay (so Saturday/Sunday--the complement to BDay, maybe WDay?) and Easter (one of the more tricky given the holidays but dateutil has most of the work done already). I'll take these. |
I would call |
I would like to get some thoughts on HolidayOffset and the next logical step of HolidayCalendar. I worked extensively with these in the past so have some ideas.
|
@rockg there is already some functionaility in 0.12, see here. http://pandas.pydata.org/pandas-docs/dev/timeseries.html#custom-business-days-experimental |
@jreback it was sent too early... The functionality I would provide would allow for holidays to be retrieved from pandas in a nice way, but I need to understand what the expectations are for what lives in pandas vs not. In general
So, if we create a generic HolidayOffset would pandas then hold definitions for other holiday rules (i.e., would pandas have NewYears, LaborDay, MemorialDay, UKBankHoliday etc.)? An argument into some of these would be the observance when creating an instance of the class. Further, would pandas implement various holiday calendars (e.g., US, UK, CME, etc.) or would these subclasses just be for users to implement? |
Calendars are a bit tricky; I in fact do keep separate calendar for each country (or you could have a sub-entity as well, e.g. CME/NYSE). Thus the numpy calendar facility DOES become attractive (though maybe should be wrapped). To allow instantiation of calendars that are then passed simply to a BDay (or CDay) type of object. I think an extension along those lines would be pretty useful. |
The numpy calendars are missing a lot of nuances and still need a list of holidays to pass in. Nevertheless, I think it's in keeping with how things have been implemented so far so I will subclass. So the expectation is that pandas will have the definitions for some basic set of holidays and calendar observances? |
@rockg I would have some 'standard' calendar sublcasses, with each holiday added thru a method, then its easy to create a 'new' calender, just sub-class your starting one, and add some holidays. |
@rockg should take year / country combination as parameters (as some holidays are only in certain years). you can have country sub-classes with lots of holiday definitions and various bizness sub-class to that. |
@jreback Back to Year offset, there's not a Month offset either, but I simply use DateOffset(months/years=n). Probably still worth having explicit classes for these. |
@rockg duh! but I agreee....having explicity Month/Year would be nice |
This is solved by subtracting |
related is #4637 (on freq for WeekDay)
This might be expected, e.g. it conforms the values. or is this a bug?
The text was updated successfully, but these errors were encountered: