Skip to content
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

Implement scalar shift_month mirroring tslib.shift_months #18218

Merged
merged 8 commits into from
Nov 12, 2017
Prev Previous commit
Next Next commit
edit per reviewer request
  • Loading branch information
jbrockmendel committed Nov 11, 2017
commit b227298d177100b45a2cd8578658ee870e8d761f
10 changes: 6 additions & 4 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cimport numpy as np
np.import_array()


from util cimport is_string_object
from util cimport is_string_object, is_integer_object

from pandas._libs.tslib import pydt_to_i8, monthrange
Copy link
Contributor

@jreback jreback Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob should move monthrange and everything in its impl to offsets (and then you can cimport these to tslib.pyx)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually. We've got a few more of these left to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, add to the list


Expand Down Expand Up @@ -381,7 +381,8 @@ class BaseOffset(_BaseOffset):
# RelativeDelta Arithmetic


cpdef datetime shift_month(datetime stamp, int months, object day_opt=None):
cpdef datetime shift_month(datetime stamp, int months,
object day_opt=None) except? -1:
"""
Given a datetime (or Timestamp) `stamp`, an integer `months` and an
option `day_opt`, return a new datetimelike that many months later,
Expand Down Expand Up @@ -423,7 +424,8 @@ cpdef datetime shift_month(datetime stamp, int months, object day_opt=None):
day = 1
elif day_opt == 'end':
day = dim
else:
# assume this is an integer (and a valid day)
elif is_integer_object(day_opt):
day = min(day_opt, dim)
else:
raise ValueError(day_opt)
return stamp.replace(year=year, month=month, day=day)