-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Refactor _TimeOp._validate to separate datetime vs timedelta vs dateoffset #18832
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
49aa384
refactor ops to isolate datetime and timedelta logic
jbrockmendel 1d7903e
revert out of scope
jbrockmendel 2809a41
Revert out of scope
jbrockmendel d005760
revert out of scope
jbrockmendel 06bf523
make test more explicit
jbrockmendel cbc04b7
rename duplicate test
jbrockmendel a3cab61
edits per request; parametrize tests
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -960,8 +960,51 @@ def test_timedelta64_ops_nat(self): | |
assert_series_equal(timedelta_series / nan, | ||
nat_series_dtype_timedelta) | ||
|
||
@pytest.mark.parametrize('scalar_td', [timedelta(minutes=5, seconds=4), | ||
Timedelta(minutes=5, seconds=4), | ||
Timedelta('5m4s').to_timedelta64()]) | ||
def test_operators_timedelta64_with_timedelta(self, scalar_td): | ||
# smoke tests | ||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
td1.iloc[2] = np.nan | ||
|
||
td1 + scalar_td | ||
scalar_td + td1 | ||
td1 - scalar_td | ||
scalar_td - td1 | ||
td1 / scalar_td | ||
scalar_td / td1 | ||
|
||
@pytest.mark.parametrize('scalar_td', [ | ||
timedelta(minutes=5, seconds=4), | ||
pytest.param(Timedelta('5m4s'), | ||
marks=pytest.mark.xfail(reason="Timedelta.__floordiv__ " | ||
"bug GH#18846")), | ||
Timedelta('5m4s').to_timedelta64()]) | ||
def test_operators_timedelta64_with_timedelta_invalid(self, scalar_td): | ||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
td1.iloc[2] = np.nan | ||
|
||
# check that we are getting a TypeError | ||
# with 'operate' (from core/ops.py) for the ops that are not | ||
# defined | ||
pattern = 'operate|unsupported|cannot' | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
td1 * scalar_td | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td * td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
td1 // scalar_td | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td // td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td ** td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
td1 ** scalar_td | ||
|
||
|
||
class TestDatetimeSeriesArithmetic(object): | ||
|
||
def test_operators_datetimelike(self): | ||
def run_ops(ops, get_ser, test_ser): | ||
|
||
|
@@ -976,16 +1019,6 @@ def run_ops(ops, get_ser, test_ser): | |
# ## timedelta64 ### | ||
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. is this initialization code then used below? 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. Yes. |
||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
td1.iloc[2] = np.nan | ||
td2 = timedelta(minutes=5, seconds=4) | ||
ops = ['__mul__', '__floordiv__', '__pow__', '__rmul__', | ||
'__rfloordiv__', '__rpow__'] | ||
run_ops(ops, td1, td2) | ||
td1 + td2 | ||
td2 + td1 | ||
td1 - td2 | ||
td2 - td1 | ||
td1 / td2 | ||
td2 / td1 | ||
|
||
# ## datetime64 ### | ||
dt1 = Series([Timestamp('20111230'), Timestamp('20120101'), | ||
|
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.
I guess this is ok for now. Maybe should make 3 sub-classes here (or I think ultimately refactoring to have all this logic in the index methods as it already duplicates some of this).