-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support for "52–53-week fiscal year" / "4–4–5 calendar" and LastWeekOfMonth DateOffset #5004
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
Right now I am using the variable |
@cancan101 Looks like u need a rebase. Can you also squash/reword most of these commits? Maybe leave 1 or 2 with a moderate amount of detail in the commit message. Thanks |
@cpcloud Rebased and squashed. |
@cancan101 can this be done as a parameter instead of creating new classes? |
Do you mean instead of creating five new public classes and two private classes, just create 3 public classes? If so, probably, there is minimal code in two of the classes. That being said, downstream use of parameters seem clunky. See for example #5015 and some of our discussions here: #4511 (comment) Or do you mean using parameters instead of creating any new classes? |
@cancan101 I like your `LastWeekInMonth |
You could also try an enum-like class (or toplevel defitinition) that has members that define each frequency in translation, so you'd do this: class Offsets(object):
LastWeekOfMonth = 'LWM'
Day = 'D'
Week = 'W'
BusinessDay = 'B' and then put the class in the toplevel namespace of pandas. Not sure if it would be better, but it might help resolve this. I too don't like putting so many new classes in. |
@jreback @jtratner Reducing the number of classes should not be too hard. That being said I still think it makes sense to add three classes: Also to be clear, these new Offsets are not the standard fiscal year/ quarter but rather the "retail fiscal year" aka 52-53 week years. |
bump |
needs a rebase .. some changes in |
There should be release notes. Are more needed? |
I ok with those classes. |
@cancan101 I meant that there were recently some changes in |
can you put a couple of possibilites up? |
@cancan101 @jreback did you mean reduce the number of classes altogether or just reduce the number of public classes? If you combine classes, use a classmethod that takes a rulecode and spits out the correct offset. |
For the yearly offset: For the quarterly-offset: These are hard to read since after the initial dash, there is no other delimitation. Further because of the regex I referred to in #5015, the number must be the first character after the dash. Question: Will anything break if one @jtratner What do you mean by creating a "classmethod that takes a rulecode and spits out the correct offset."? Are your referring to the idea I suggested in #5028? |
Given that I am going to add just |
No, that's not what I mean. What I mean is that you might want to let people use a class without having to pass all the arguments to the constructor. For example, here's what we did in TimeOp so that |
@jtratner I don't really follow what would be the point of that method here. |
Didn't realize you only had two at this point. |
@jtratner Theoretically these could be merged into You could then merge { |
Otherwise as far as my reading of Wikipedia and subsequent research has gone, there are only two variations of the 52-53 week calendar. |
Sounds like you've spent a lot of time thinking about this! |
@cancan101 can you rebase and update? |
@jreback Can I get some feedback on the rule code? |
@@ -367,9 +369,27 @@ def get_period_alias(offset_str): | |||
|
|||
for _i, _weekday in enumerate(['MON', 'TUE', 'WED', 'THU', 'FRI']): |
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.
just define a no argument function (add add global
declarations where necessary) and call it. then you don't need to have all these underscored variables (obviously keep the ones that were there before)
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.
@cpcloud What do you think about moving this logic to a classmethod on the respective offsets?
Also I am not quite sure what you mean by the function.
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.
classmethod probably ok....
by function i just meant something like
def initializer():
# your init code here
initializer()
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.
The idea with classmethods is to put the logic for generating all instances of a given offset with the offset itself rather than having the code in separate files
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.
initializer for now
|
Any idea what changed? |
Also, what is wrong with doing the math on a datetime?
|
this is your code, you probably have some relativedelata stuff in there which is not returning the correct type |
Okay, I can take a closer look. I assume relativedelata returns a datetime? |
not much has been merged recently....can you pinpoint what commit it last worked? |
I'll see what I can come up with |
Use git reflog to grab your pre-rebase branch. Can you try doing arithmetic That is a very weird error to get - suggests there is (potentially) some |
The error occurs when subtracting a Timestamp from a datetime type. git bisect found that the problem was introduced to master with commit 02158e6 on September 30th. I will just have a close look on that one. |
That weird. I'm pretty sure I had rebased more recently to get @jtratner's change for Offset construction. |
in tslib.pyx class _Timestamp(datetime), method sub datetime.__sub__(self, other) was replaced by super(_Timestamp, self).__sub__(other) As _Timestamp is a direct subtype of datetime.datetime, the result should be the same. But the latter case leads to the error
I have no clue why self in _Timestamp is not an instance or subtype ot _Timestamp. |
@cancan101 just revert that one line
they don't act the same because _Timestamp is a shadow class (of a c-lass) AFAIK.. |
@cpcloud Thoughts? |
@cancan101 Could you add a test for subtracting a datetime from a timestamp to test_tslib.py as well? |
Sure. |
Hurray for git bisect - which is why you want every commit to at least |
Issues should be fixed.
|
Okay, please rebase on top of latest master if you haven't already
|
Is it not merge able? If not I'll rebate.
|
You need to rebase because this previously failed after rebasing (wasn't |
Np. Rebased and pushed. Easy enough. Should be running tests now. |
passed |
LastWeekOfMonth DateOffset. - Added ``LastWeekOfMonth`` DateOffset - Added ``FY5253 and ``FY5253Quarter`` DateOffsets
@jtratner What can I do to get this merged in? I rebased earlier today |
ENH: Support for "52–53-week fiscal year" / "4–4–5 calendar" and LastWeekOfMonth DateOffset
there you go :) |
Closes #4511 and #4637
LastWeekOfMonth
DateOffset LastWeekOfMonth DateOffset #4637FY5253
, andFY5253Quarter
DateOffsets ENH: Support for "52–53-week fiscal year" / "4–4–5 calendar" #4511get_freq_code
,_period_str_to_code
and_base_and_stride