diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 7509c502f27ed..473a4bb72e6d9 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1245,7 +1245,6 @@ Offsets - Bug in :class:`FY5253` where ``datetime`` addition and subtraction incremented incorrectly for dates on the year-end but not normalized to midnight (:issue:`18854`) - Bug in :class:`FY5253` where date offsets could incorrectly raise an ``AssertionError`` in arithmetic operations (:issue:`14774`) - Numeric ^^^^^^^ - Bug in :class:`Series` constructor with an int or float list where specifying ``dtype=str``, ``dtype='str'`` or ``dtype='U'`` failed to convert the data elements to strings (:issue:`16605`) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index b015495b095b6..59589478f48f5 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -402,7 +402,8 @@ Timezones Offsets ^^^^^^^ -- +- Bug in :class:`FY5253` where date offsets could incorrectly raise an ``AssertionError`` in arithmetic operatons (:issue:`14774`) +- Bug in :class:`DateOffset` where keyword arguments ``week`` and ``milliseconds`` were accepted and ignored. Passing these will now raise ``ValueError`` (:issue:`19398`) - Numeric diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7881529f04ed3..3ba2270a851d5 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -254,10 +254,10 @@ def _validate_business_time(t_input): relativedelta_kwds = set([ 'years', 'months', 'weeks', 'days', - 'year', 'month', 'week', 'day', 'weekday', + 'year', 'month', 'day', 'weekday', 'hour', 'minute', 'second', 'microsecond', 'nanosecond', 'nanoseconds', - 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds']) + 'hours', 'minutes', 'seconds', 'microseconds']) def _determine_offset(kwds): diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index db69bfadfcf49..35ee0d37e2b1a 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -3085,6 +3085,13 @@ def test_valid_month_attributes(kwd, month_classes): cls(**{kwd: 3}) +@pytest.mark.parametrize('kwd', sorted(list(liboffsets.relativedelta_kwds))) +def test_valid_relativedelta_kwargs(kwd): + # Check that all the arguments specified in liboffsets.relativedelta_kwds + # are in fact valid relativedelta keyword args + DateOffset(**{kwd: 1}) + + @pytest.mark.parametrize('kwd', sorted(list(liboffsets.relativedelta_kwds))) def test_valid_tick_attributes(kwd, tick_classes): # GH#18226 diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 5d076bf33a8ac..dd4356aac1cd5 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -158,6 +158,54 @@ def __add__(date): date + BDay(0) == BDay.rollforward(date) Since 0 is a bit weird, we suggest avoiding its use. + + Parameters + ---------- + n : int, default 1 + The number of time periods the offset represents. + normalize : bool, default False + Whether to round the result of a DateOffset addition down to the + previous midnight. + **kwds + Temporal parameter that add to or replace the offset value. + + Parameters that **add** to the offset (like Timedelta): + + - years + - months + - weeks + - days + - hours + - minutes + - seconds + - microseconds + - nanoseconds + + Parameters that **replace** the offset value: + + - year + - month + - day + - weekday + - hour + - minute + - second + - microsecond + - nanosecond + + See Also + -------- + dateutil.relativedelta.relativedelta + + Examples + -------- + >>> ts = pd.Timestamp('2017-01-01 09:10:11') + >>> ts + DateOffset(months=3) + Timestamp('2017-04-01 09:10:11') + + >>> ts = pd.Timestamp('2017-01-01 09:10:11') + >>> ts + DateOffset(month=3) + Timestamp('2017-03-01 09:10:11') """ _params = cache_readonly(BaseOffset._params.fget) _use_relativedelta = False