-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Tslibs offsets validation #18210
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
Tslibs offsets validation #18210
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18210 +/- ##
==========================================
- Coverage 91.4% 91.38% -0.02%
==========================================
Files 163 163
Lines 50064 50055 -9
==========================================
- Hits 45759 45744 -15
- Misses 4305 4311 +6
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18210 +/- ##
==========================================
- Coverage 91.36% 91.35% -0.02%
==========================================
Files 164 164
Lines 49718 49709 -9
==========================================
- Hits 45426 45410 -16
- Misses 4292 4299 +7
Continue to review full report at Codecov.
|
The time_asof and time_asof_nan are pretty frequently outliers. Given the local entropy field, this is about a wash. |
return t_input | ||
else: | ||
raise ValueError("time data must be string or datetime.time") | ||
|
||
|
||
def _validate_n(n): |
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.
Docstring on all of these functions.
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.
Will do.
pandas/tests/tseries/test_offsets.py
Outdated
@@ -2192,7 +2192,7 @@ def test_repr(self): | |||
def test_corner(self): | |||
pytest.raises(ValueError, Week, weekday=7) | |||
tm.assert_raises_regex( | |||
ValueError, "Day must be", Week, weekday=-1) | |||
ValueError, "weekday must be", Week, weekday=-1) |
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.
Why are we changing all of these "Day" strings to "weekday" ?
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.
Because the incorrect argument is "weekday". Many of these also take a "day" argument, so there is potential for ambiguity.
raise ValueError("N cannot be 0") | ||
|
||
|
||
def _validate_month(month): |
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 reason that these are not instance methods of BaseOffset?
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.
My default is to not make something a method if it doesn't require self
.
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.
this is not the current style. agree that these are somewhat of an edge case, but don't change just for the sake of change or its 'your style', prefer to keep the existing code style unless good reason to change.
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.
OK. The fix to the error message in validate_weekday is probably worthwhile. Should I revert the others?
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 like them in cython, but these make more sense as methods I think as they do use self
at least for some)
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.
as they do use self at least for some
None of the ones implemented here.
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.
right but the point is you don't need the allow_none arg if you simply make this a method (for the weekday one)
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.
How does making it a method change whether allow_none
is needed?
travis error is TestClipboard |
|
||
Parameters | ||
---------- | ||
month : int |
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 would guess we have this type of method in multiple places (though I agree these should actually be in this module).
…libs-offsets-validation
…libs-offsets-validation
|
||
|
||
def _validate_weekday(weekday, allow_none=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.
if this is a method, then you don't need allow_none (which is a really odd non-standard kw).
because you are a method, checking self.weekday
is obvious.
now you can also have a _validate_weekday method that does everything (but the allow_none) and simply call that if you want.
If you show that you need these in multiple places, then certainly you can call them, from the offsets you need to have a method.
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 still don't totally understand the reasoning, but it sounds like the upshot here is that to get this done _validate_weekday
needs to become a method of _BaseOffset
, and without a allow_none
kwarg. Is that the correct takeaway?
…libs-offsets-validation
…libs-offsets-validation
isn't this competing with #18228 ? thought was closing this one |
needs a rebase (and prob some code removal) |
Low priority, closing for now |
Lots to do in offsets, trying to push breaking changes to the very end. This just implements validation for DateOffset args/kwargs, fixes a poorly-worded error message and the associated tm.assert_raises_regex tests.
git diff upstream/master -u -- "*.py" | flake8 --diff