Skip to content

Commit 601b8c9

Browse files
jbrockmendeljreback
authored andcommitted
Make DateOffset.kwds a property (pandas-dev#19403)
1 parent 7db4bea commit 601b8c9

File tree

5 files changed

+78
-72
lines changed

5 files changed

+78
-72
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ Other API Changes
341341
- :func:`DatetimeIndex.shift` and :func:`TimedeltaIndex.shift` will now raise ``NullFrequencyError`` (which subclasses ``ValueError``, which was raised in older versions) when the index object frequency is ``None`` (:issue:`19147`)
342342
- Addition and subtraction of ``NaN`` from a :class:`Series` with ``dtype='timedelta64[ns]'`` will raise a ``TypeError` instead of treating the ``NaN`` as ``NaT`` (:issue:`19274`)
343343
- Set operations (union, difference...) on :class:`IntervalIndex` with incompatible index types will now raise a ``TypeError`` rather than a ``ValueError`` (:issue:`19329`)
344+
- :class:`DateOffset` objects render more simply, e.g. "<DateOffset: days=1>" instead of "<DateOffset: kwds={'days': 1}>" (:issue:`19403`)
344345

345346
.. _whatsnew_0230.deprecations:
346347

pandas/_libs/tslibs/offsets.pyx

+8
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ class _BaseOffset(object):
302302
_normalize_cache = True
303303
_cacheable = False
304304
_day_opt = None
305+
_attributes = frozenset(['n', 'normalize'])
306+
307+
@property
308+
def kwds(self):
309+
# for backwards-compatibility
310+
kwds = {name: getattr(self, name, None) for name in self._attributes
311+
if name not in ['n', 'normalize']}
312+
return {name: kwds[name] for name in kwds if kwds[name] is not None}
305313

306314
def __call__(self, other):
307315
return self.apply(other)

pandas/core/indexes/datetimes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ def f(self):
7171
if field in ['is_month_start', 'is_month_end',
7272
'is_quarter_start', 'is_quarter_end',
7373
'is_year_start', 'is_year_end']:
74-
month_kw = (self.freq.kwds.get('startingMonth',
75-
self.freq.kwds.get('month', 12))
76-
if self.freq else 12)
74+
freq = self.freq
75+
month_kw = 12
76+
if freq:
77+
kwds = freq.kwds
78+
month_kw = kwds.get('startingMonth', kwds.get('month', 12))
7779

7880
result = fields.get_start_end_field(values, field,
7981
self.freqstr, month_kw)

pandas/tests/tseries/offsets/test_offsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_offset_freqstr(self, offset_types):
218218

219219
freqstr = offset.freqstr
220220
if freqstr not in ('<Easter>',
221-
"<DateOffset: kwds={'days': 1}>",
221+
"<DateOffset: days=1>",
222222
'LWOM-SAT', ):
223223
code = get_offset(freqstr)
224224
assert offset.rule_code == code

0 commit comments

Comments
 (0)