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

Make DateOffset.kwds a property #19403

Merged
merged 4 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ class _BaseOffset(object):
_normalize_cache = True
_cacheable = False
_day_opt = None
_attributes = frozenset(['n', 'normalize'])

@property
def kwds(self):
# for backwards-compatibility
kwds = {name: getattr(self, name, None) for name in self._attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

huh?

Copy link
Member Author

Choose a reason for hiding this comment

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

In particular DateOffset has a lot of _attributes that may not get set unless specifically passed.

if name not in ['n', 'normalize']}
return {name: kwds[name] for name in kwds if kwds[name] is not None}

def __call__(self, other):
return self.apply(other)
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def f(self):
if field in ['is_month_start', 'is_month_end',
'is_quarter_start', 'is_quarter_end',
'is_year_start', 'is_year_end']:
month_kw = (self.freq.kwds.get('startingMonth',
self.freq.kwds.get('month', 12))
if self.freq else 12)
freq = self.freq
month_kw = 12
if freq:
kwds = freq.kwds
month_kw = kwds.get('startingMonth', kwds.get('month', 12))

result = fields.get_start_end_field(values, field,
self.freqstr, month_kw)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_offset_freqstr(self, offset_types):

freqstr = offset.freqstr
if freqstr not in ('<Easter>',
"<DateOffset: kwds={'days': 1}>",
"<DateOffset: days=1>",
Copy link
Contributor

Choose a reason for hiding this comment

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

need a whatsnew note, explainig that the repr changed

Copy link
Contributor

Choose a reason for hiding this comment

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

did the repr change break anything? can you add some tests for this (doesn't have to be comprehensive, but some basic ones is ok)

'LWOM-SAT', ):
code = get_offset(freqstr)
assert offset.rule_code == code
Expand Down
Loading