-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Lock down kwargs in offsets signatures #17458
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5e276c9
Lock down kwargs in offsets signatures
jbrockmendel 0183e50
whatsnew note
jbrockmendel e33626e
Merge branch 'master' of https://github.com/pandas-dev/pandas into of…
jbrockmendel 1377df1
Merge branch 'master' of https://github.com/pandas-dev/pandas into of…
jbrockmendel ed78a4a
restrict YearOffset to month kwarg
jbrockmendel 36290d2
Restrict SemiMonthOffset kwargs to day_of_month
jbrockmendel 4443d6c
Lock down kwargs in FY5253 and FY5253Quarter
jbrockmendel 8cb6b66
lock down kwargs in BusinessDay, CustomBusinessMonthEnd
jbrockmendel fe7bb56
Lockdown kwargs in remaining DateOffset subclasses
jbrockmendel 3daab66
Briefer WhatsNew, add missing kwds attrs
jbrockmendel aefb68c
whitespace fixups
jbrockmendel 1e06d99
Move doc section to other api changes bullet point
jbrockmendel 7be31da
Merge branch 'master' into offset_sigs
jbrockmendel cd1f224
Add pickle tests for 0.19.2 and 0.20.3
jbrockmendel 97c896e
Merge branch 'offset_sigs' of https://github.com/jbrockmendel/pandas …
jbrockmendel e93de50
Merge branch 'master' of https://github.com/pandas-dev/pandas into of…
jbrockmendel 7426265
Merge branch 'master' of https://github.com/pandas-dev/pandas into of…
jbrockmendel aee75de
New version of test_pickle_v0_20_3
jbrockmendel cc5a71a
flake8 whitespace fixup
jbrockmendel 521a8d0
Merge branch 'master' of https://github.com/pandas-dev/pandas into of…
jbrockmendel 217a558
remove test per reviewer instruction
jbrockmendel 086b485
Add offsets with kwds to generate_legacy_storage_files
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1571,18 +1571,18 @@ class Week(DateOffset): | |
""" | ||
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
def __init__(self, n=1, normalize=False, weekday=None): | ||
self.n = n | ||
self.normalize = normalize | ||
self.weekday = kwds.get('weekday', None) | ||
self.weekday = weekday | ||
|
||
if self.weekday is not None: | ||
if self.weekday < 0 or self.weekday > 6: | ||
raise ValueError('Day must be 0<=day<=6, got {day}' | ||
.format(day=self.weekday)) | ||
|
||
self._inc = timedelta(weeks=1) | ||
self.kwds = kwds | ||
self.kwds = {'weekday': weekday} | ||
|
||
def isAnchored(self): | ||
return (self.n == 1 and self.weekday is not None) | ||
|
@@ -1674,9 +1674,9 @@ class WeekOfMonth(DateOffset): | |
Parameters | ||
---------- | ||
n : int | ||
week : {0, 1, 2, 3, ...} | ||
week : {0, 1, 2, 3, ...}, default None | ||
0 is 1st week of month, 1 2nd week, etc. | ||
weekday : {0, 1, ..., 6} | ||
weekday : {0, 1, ..., 6}, default None | ||
0: Mondays | ||
1: Tuesdays | ||
2: Wednesdays | ||
|
@@ -1688,11 +1688,11 @@ class WeekOfMonth(DateOffset): | |
|
||
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
def __init__(self, n=1, normalize=False, week=None, weekday=None): | ||
self.n = n | ||
self.normalize = normalize | ||
self.weekday = kwds['weekday'] | ||
self.week = kwds['week'] | ||
self.weekday = weekday | ||
self.week = week | ||
|
||
if self.n == 0: | ||
raise ValueError('N cannot be 0') | ||
|
@@ -1704,7 +1704,7 @@ def __init__(self, n=1, normalize=False, **kwds): | |
raise ValueError('Week must be 0<=week<=3, got {week}' | ||
.format(week=self.week)) | ||
|
||
self.kwds = kwds | ||
self.kwds = {'weekday': weekday, 'week': week} | ||
|
||
@apply_wraps | ||
def apply(self, other): | ||
|
@@ -1774,21 +1774,22 @@ class LastWeekOfMonth(DateOffset): | |
|
||
Parameters | ||
---------- | ||
n : int | ||
weekday : {0, 1, ..., 6} | ||
n : int, default 1 | ||
weekday : {0, 1, ..., 6}, default None | ||
0: Mondays | ||
1: Tuesdays | ||
2: Wednesdays | ||
3: Thursdays | ||
4: Fridays | ||
5: Saturdays | ||
6: Sundays | ||
|
||
""" | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
def __init__(self, n=1, normalize=False, weekday=None): | ||
self.n = n | ||
self.normalize = normalize | ||
self.weekday = kwds['weekday'] | ||
self.weekday = weekday | ||
|
||
if self.n == 0: | ||
raise ValueError('N cannot be 0') | ||
|
@@ -1797,7 +1798,7 @@ def __init__(self, n=1, normalize=False, **kwds): | |
raise ValueError('Day must be 0<=day<=6, got {day}' | ||
.format(day=self.weekday)) | ||
|
||
self.kwds = kwds | ||
self.kwds = {'weekday': weekday} | ||
|
||
@apply_wraps | ||
def apply(self, other): | ||
|
@@ -1861,13 +1862,14 @@ class QuarterOffset(DateOffset): | |
# TODO: Consider combining QuarterOffset and YearOffset __init__ at some | ||
# point | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
def __init__(self, n=1, normalize=False, startingMonth=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make an issue that this should be deprecated to |
||
self.n = n | ||
self.normalize = normalize | ||
self.startingMonth = kwds.get('startingMonth', | ||
self._default_startingMonth) | ||
if startingMonth is None: | ||
startingMonth = self._default_startingMonth | ||
self.startingMonth = startingMonth | ||
|
||
self.kwds = kwds | ||
self.kwds = {'startingMonth': startingMonth} | ||
|
||
def isAnchored(self): | ||
return (self.n == 1 and self.startingMonth is not None) | ||
|
@@ -1985,13 +1987,6 @@ class QuarterEnd(QuarterOffset): | |
_default_startingMonth = 3 | ||
_prefix = 'Q' | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
self.n = n | ||
self.normalize = normalize | ||
self.startingMonth = kwds.get('startingMonth', 3) | ||
|
||
self.kwds = kwds | ||
|
||
def isAnchored(self): | ||
return (self.n == 1 and self.startingMonth is not None) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a test for this as weekday=None? isn't that an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an error, though a different one in Py2 vs Py3. In the status quo not passing a weekday explicitly will raise a KeyError. Default to Monday I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no if weekday is None, just raise a value error, in reality this should actually be the first (and a required parameter), but I guess that would be hard to change. Don't set defaults, raise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting it should be
__init__(self, weekday, n=1, normalize=False)
? I see some appeal to that, but there is a lot of symmetry with other signatures all starting with(self, n=1, normalize=False, ...)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment above. this is ok for now. actually weekday is optional, so this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things. First, here and in other places you say "this is fine" but I don't know whether you're referring to the PR or the thing the PR is fixing. Based on the go-ahead you've given below to look over timeseries.rst I'm assuming you mean the PR version is fine, just heads up for ways I'm liable to get confused next time around.
Under the status quo, failing to pass
weekday
raises aKeyError
. In the PR, not passing anything will raise a ValueError in py2 and TypeError in py3. (The same errors would result in the status quo if a user passedNone
explicitly)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never mean this entire PR is fine. If that was the case I wouldn't have any other comments. Individual comments are revering to the specific line/section where I make it.