-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Prevent passing invalid kwds to DateOffset constructors #18226
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
jreback
merged 35 commits into
pandas-dev:master
from
jbrockmendel:tslibs-offsets-inits
Nov 25, 2017
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b9fe60e
Patch __init__ to prevent passing invalid kwds
jbrockmendel f10a1c6
cast n to integer, assert equality
jbrockmendel 807d769
whatsnew note
jbrockmendel 687e3b7
parameterize tests, define fixture where it is used
jbrockmendel d5443ca
fixup
jbrockmendel 5e5e0c0
exclude base classes from testing
jbrockmendel 17f7b5a
exclude base classes from testing
jbrockmendel 3834ef8
dummy commit to force CI
jbrockmendel 1c54e96
edits per reviewer suggestions
jbrockmendel 0e37a24
whatsnew whitespace
jbrockmendel a572368
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel d0ff381
whitespace fixup
jbrockmendel 409dbd0
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel 6a9233e
break up hour test to debug appveyor error (segfault?)
jbrockmendel 4406df8
break down segfaulting test to debug
jbrockmendel 44891cd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel 573abb6
fixturize
jbrockmendel c6cc8bc
troubleshoot segfault by moving __eq__ to _BaseOffset
jbrockmendel a68f4a7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel c8224c1
try sorting rd_kwds to fix segfault, revert other troubleshooting gue…
jbrockmendel 55779d8
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel d5b8302
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel b54e26b
implement _validate_n method
jbrockmendel fade4a2
test for _validate_n
jbrockmendel 38c2238
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel fe895ff
Raise TypeError, not ValueError
jbrockmendel 11ba1a9
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel bc90a19
Catch ValueError in int(n)
jbrockmendel 0b3dca0
fixup extra imports
jbrockmendel 9c841fc
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel adee395
remove unnecessary re-definitions, add tests, improve error msg
jbrockmendel 43dc17e
Add docstring to validate_n
jbrockmendel 4ff8c22
fixup missing format
jbrockmendel d261be9
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel b4b9e15
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
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
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
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
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import date, datetime, timedelta | ||
import functools | ||
import operator | ||
|
||
from datetime import date, datetime, timedelta | ||
from pandas.compat import range | ||
from pandas import compat | ||
import numpy as np | ||
|
@@ -166,7 +166,7 @@ def __add__(date): | |
normalize = False | ||
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.kwds = kwds | ||
|
||
|
@@ -473,7 +473,7 @@ class BusinessDay(BusinessMixin, SingleConstructorOffset): | |
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False, offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.kwds = {'offset': offset} | ||
self._offset = offset | ||
|
@@ -782,7 +782,7 @@ class BusinessHour(BusinessHourMixin, SingleConstructorOffset): | |
|
||
def __init__(self, n=1, normalize=False, start='09:00', | ||
end='17:00', offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
super(BusinessHour, self).__init__(start=start, end=end, offset=offset) | ||
|
||
|
@@ -819,7 +819,7 @@ class CustomBusinessDay(BusinessDay): | |
|
||
def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri', | ||
holidays=None, calendar=None, offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self._offset = offset | ||
self.kwds = {} | ||
|
@@ -887,7 +887,7 @@ class CustomBusinessHour(BusinessHourMixin, SingleConstructorOffset): | |
def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri', | ||
holidays=None, calendar=None, | ||
start='09:00', end='17:00', offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
super(CustomBusinessHour, self).__init__(start=start, | ||
end=end, offset=offset) | ||
|
@@ -919,6 +919,11 @@ def next_bday(self): | |
class MonthOffset(SingleConstructorOffset): | ||
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False): | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.kwds = {} | ||
|
||
@property | ||
def name(self): | ||
if self.isAnchored: | ||
|
@@ -994,7 +999,8 @@ def __init__(self, n=1, normalize=False, day_of_month=None): | |
msg = 'day_of_month must be {min}<=day_of_month<=27, got {day}' | ||
raise ValueError(msg.format(min=self._min_day_of_month, | ||
day=self.day_of_month)) | ||
self.n = int(n) | ||
|
||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.kwds = {'day_of_month': self.day_of_month} | ||
|
||
|
@@ -1205,7 +1211,7 @@ class CustomBusinessMonthEnd(BusinessMixin, MonthOffset): | |
|
||
def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri', | ||
holidays=None, calendar=None, offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self._offset = offset | ||
self.kwds = {} | ||
|
@@ -1278,7 +1284,7 @@ class CustomBusinessMonthBegin(BusinessMixin, MonthOffset): | |
|
||
def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri', | ||
holidays=None, calendar=None, offset=timedelta(0)): | ||
self.n = int(n) | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self._offset = offset | ||
self.kwds = {} | ||
|
@@ -1345,7 +1351,7 @@ class Week(EndMixin, DateOffset): | |
_prefix = 'W' | ||
|
||
def __init__(self, n=1, normalize=False, weekday=None): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.weekday = weekday | ||
|
||
|
@@ -1424,7 +1430,7 @@ class WeekOfMonth(DateOffset): | |
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False, week=None, weekday=None): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.weekday = weekday | ||
self.week = week | ||
|
@@ -1509,7 +1515,7 @@ class LastWeekOfMonth(DateOffset): | |
_prefix = 'LWOM' | ||
|
||
def __init__(self, n=1, normalize=False, weekday=None): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.weekday = weekday | ||
|
||
|
@@ -1575,7 +1581,7 @@ class QuarterOffset(DateOffset): | |
# point | ||
|
||
def __init__(self, n=1, normalize=False, startingMonth=None): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
if startingMonth is None: | ||
startingMonth = self._default_startingMonth | ||
|
@@ -1820,7 +1826,7 @@ class FY5253(DateOffset): | |
|
||
def __init__(self, n=1, normalize=False, weekday=0, startingMonth=1, | ||
variation="nearest"): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.startingMonth = startingMonth | ||
self.weekday = weekday | ||
|
@@ -2032,7 +2038,7 @@ class FY5253Quarter(DateOffset): | |
|
||
def __init__(self, n=1, normalize=False, weekday=0, startingMonth=1, | ||
qtr_with_extra_week=1, variation="nearest"): | ||
self.n = n | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
|
||
self.weekday = weekday | ||
|
@@ -2158,6 +2164,11 @@ class Easter(DateOffset): | |
""" | ||
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False): | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
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. same (and for other ones you are adding) |
||
self.kwds = {} | ||
|
||
@apply_wraps | ||
def apply(self, other): | ||
current_easter = easter(other.year) | ||
|
@@ -2199,6 +2210,12 @@ class Tick(SingleConstructorOffset): | |
_inc = Timedelta(microseconds=1000) | ||
_prefix = 'undefined' | ||
|
||
def __init__(self, n=1, normalize=False): | ||
# TODO: do Tick classes with normalize=True make sense? | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.kwds = {} | ||
|
||
__gt__ = _tick_comp(operator.gt) | ||
__ge__ = _tick_comp(operator.ge) | ||
__lt__ = _tick_comp(operator.lt) | ||
|
@@ -2257,6 +2274,7 @@ def delta(self): | |
def nanos(self): | ||
return delta_to_nanoseconds(self.delta) | ||
|
||
# TODO: Should Tick have its own apply_index? | ||
def apply(self, other): | ||
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps | ||
if isinstance(other, Timestamp): | ||
|
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.
can you add some more tests here, e.g. for passing floats != to the int