Skip to content

Commit 1f6ddc4

Browse files
jbrockmendeljreback
authored andcommitted
Fix invalid relativedelta_kwds (#19398)
1 parent b9c1786 commit 1f6ddc4

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

doc/source/whatsnew/v0.23.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,6 @@ Offsets
12451245
- Bug in :class:`FY5253` where ``datetime`` addition and subtraction incremented incorrectly for dates on the year-end but not normalized to midnight (:issue:`18854`)
12461246
- Bug in :class:`FY5253` where date offsets could incorrectly raise an ``AssertionError`` in arithmetic operations (:issue:`14774`)
12471247

1248-
12491248
Numeric
12501249
^^^^^^^
12511250
- 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`)

doc/source/whatsnew/v0.24.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ Timezones
404404
Offsets
405405
^^^^^^^
406406

407-
-
407+
- Bug in :class:`FY5253` where date offsets could incorrectly raise an ``AssertionError`` in arithmetic operatons (:issue:`14774`)
408+
- Bug in :class:`DateOffset` where keyword arguments ``week`` and ``milliseconds`` were accepted and ignored. Passing these will now raise ``ValueError`` (:issue:`19398`)
408409
-
409410

410411
Numeric

pandas/_libs/tslibs/offsets.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ def _validate_business_time(t_input):
254254

255255
relativedelta_kwds = set([
256256
'years', 'months', 'weeks', 'days',
257-
'year', 'month', 'week', 'day', 'weekday',
257+
'year', 'month', 'day', 'weekday',
258258
'hour', 'minute', 'second', 'microsecond',
259259
'nanosecond', 'nanoseconds',
260-
'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds'])
260+
'hours', 'minutes', 'seconds', 'microseconds'])
261261

262262

263263
def _determine_offset(kwds):

pandas/tests/tseries/offsets/test_offsets.py

+7
Original file line numberDiff line numberDiff line change
@@ -3085,6 +3085,13 @@ def test_valid_month_attributes(kwd, month_classes):
30853085
cls(**{kwd: 3})
30863086

30873087

3088+
@pytest.mark.parametrize('kwd', sorted(list(liboffsets.relativedelta_kwds)))
3089+
def test_valid_relativedelta_kwargs(kwd):
3090+
# Check that all the arguments specified in liboffsets.relativedelta_kwds
3091+
# are in fact valid relativedelta keyword args
3092+
DateOffset(**{kwd: 1})
3093+
3094+
30883095
@pytest.mark.parametrize('kwd', sorted(list(liboffsets.relativedelta_kwds)))
30893096
def test_valid_tick_attributes(kwd, tick_classes):
30903097
# GH#18226

pandas/tseries/offsets.py

+48
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,54 @@ def __add__(date):
158158
date + BDay(0) == BDay.rollforward(date)
159159
160160
Since 0 is a bit weird, we suggest avoiding its use.
161+
162+
Parameters
163+
----------
164+
n : int, default 1
165+
The number of time periods the offset represents.
166+
normalize : bool, default False
167+
Whether to round the result of a DateOffset addition down to the
168+
previous midnight.
169+
**kwds
170+
Temporal parameter that add to or replace the offset value.
171+
172+
Parameters that **add** to the offset (like Timedelta):
173+
174+
- years
175+
- months
176+
- weeks
177+
- days
178+
- hours
179+
- minutes
180+
- seconds
181+
- microseconds
182+
- nanoseconds
183+
184+
Parameters that **replace** the offset value:
185+
186+
- year
187+
- month
188+
- day
189+
- weekday
190+
- hour
191+
- minute
192+
- second
193+
- microsecond
194+
- nanosecond
195+
196+
See Also
197+
--------
198+
dateutil.relativedelta.relativedelta
199+
200+
Examples
201+
--------
202+
>>> ts = pd.Timestamp('2017-01-01 09:10:11')
203+
>>> ts + DateOffset(months=3)
204+
Timestamp('2017-04-01 09:10:11')
205+
206+
>>> ts = pd.Timestamp('2017-01-01 09:10:11')
207+
>>> ts + DateOffset(month=3)
208+
Timestamp('2017-03-01 09:10:11')
161209
"""
162210
_params = cache_readonly(BaseOffset._params.fget)
163211
_use_relativedelta = False

0 commit comments

Comments
 (0)