Skip to content

Use setdefault on kwds to standardize behavior #17443

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
29 changes: 15 additions & 14 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def __init__(self, n=1, normalize=False, **kwds):
self.n = int(n)
self.normalize = normalize
self.kwds = kwds
self.offset = kwds.get('offset', timedelta(0))
self.offset = kwds.setdefault('offset', timedelta(0))

@property
def freqstr(self):
Expand Down Expand Up @@ -708,9 +708,9 @@ def __init__(self, **kwds):
kwds['start'] = self._validate_time(kwds.get('start', '09:00'))
kwds['end'] = self._validate_time(kwds.get('end', '17:00'))
self.kwds = kwds
self.offset = kwds.get('offset', timedelta(0))
self.start = kwds.get('start', '09:00')
self.end = kwds.get('end', '17:00')
self.offset = kwds.setdefault('offset', timedelta(0))
self.start = kwds['start']
self.end = kwds['end']

def _validate_time(self, t_input):
from datetime import time as dt_time
Expand Down Expand Up @@ -977,7 +977,7 @@ def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri',
self.n = int(n)
self.normalize = normalize
self.kwds = kwds
self.offset = kwds.get('offset', timedelta(0))
self.offset = kwds.setdefault('offset', timedelta(0))
calendar, holidays = self.get_calendar(weekmask=weekmask,
holidays=holidays,
calendar=calendar)
Expand Down Expand Up @@ -1470,7 +1470,7 @@ def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri',
self.n = int(n)
self.normalize = normalize
self.kwds = kwds
self.offset = kwds.get('offset', timedelta(0))
self.offset = kwds.setdefault('offset', timedelta(0))
self.cbday = CustomBusinessDay(n=self.n, normalize=normalize,
weekmask=weekmask, holidays=holidays,
calendar=calendar, **kwds)
Expand Down Expand Up @@ -1530,7 +1530,7 @@ def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri',
self.n = int(n)
self.normalize = normalize
self.kwds = kwds
self.offset = kwds.get('offset', timedelta(0))
self.offset = kwds.setdefault('offset', timedelta(0))
self.cbday = CustomBusinessDay(n=self.n, normalize=normalize,
weekmask=weekmask, holidays=holidays,
calendar=calendar, **kwds)
Expand Down Expand Up @@ -1574,7 +1574,7 @@ class Week(DateOffset):
def __init__(self, n=1, normalize=False, **kwds):
self.n = n
self.normalize = normalize
self.weekday = kwds.get('weekday', None)
self.weekday = kwds.setdefault('weekday', None)

if self.weekday is not None:
if self.weekday < 0 or self.weekday > 6:
Expand Down Expand Up @@ -1864,8 +1864,8 @@ class QuarterOffset(DateOffset):
def __init__(self, n=1, normalize=False, **kwds):
self.n = n
self.normalize = normalize
self.startingMonth = kwds.get('startingMonth',
self._default_startingMonth)
self.startingMonth = kwds.setdefault('startingMonth',
self._default_startingMonth)

self.kwds = kwds

Expand Down Expand Up @@ -1988,7 +1988,8 @@ class QuarterEnd(QuarterOffset):
def __init__(self, n=1, normalize=False, **kwds):
self.n = n
self.normalize = normalize
self.startingMonth = kwds.get('startingMonth', 3)
self.startingMonth = kwds.setdefault('startingMonth',
self._default_startingMonth)

self.kwds = kwds

Expand Down Expand Up @@ -2063,7 +2064,7 @@ class YearOffset(DateOffset):
_adjust_dst = True

def __init__(self, n=1, normalize=False, **kwds):
self.month = kwds.get('month', self._default_month)
self.month = kwds.setdefault('month', self._default_month)

if self.month < 1 or self.month > 12:
raise ValueError('Month must go from 1 to 12')
Expand Down Expand Up @@ -2738,7 +2739,7 @@ def __eq__(self, other):
if isinstance(other, Tick):
return self.delta == other.delta
else:
return DateOffset.__eq__(self, other)
return False

# This is identical to DateOffset.__hash__, but has to be redefined here
# for Python 3, because we've redefined __eq__.
Expand All @@ -2754,7 +2755,7 @@ def __ne__(self, other):
if isinstance(other, Tick):
return self.delta != other.delta
else:
return DateOffset.__ne__(self, other)
return True

@property
def delta(self):
Expand Down