Skip to content

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 7 commits into from
Dec 23, 2017

Conversation

jbrockmendel
Copy link
Member

Trying to mirror the logic in the datetimelike index classes.

Separate some of the tests in the same vein.

No logic should be changed in this PR, it should be pure refactor.

This will have a merge conflict with #18831.

@codecov
Copy link

codecov bot commented Dec 19, 2017

Codecov Report

Merging #18832 into master will decrease coverage by 0.01%.
The diff coverage is 67.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18832      +/-   ##
==========================================
- Coverage   91.64%   91.63%   -0.02%     
==========================================
  Files         154      154              
  Lines       51408    51387      -21     
==========================================
- Hits        47113    47088      -25     
- Misses       4295     4299       +4
Flag Coverage Δ
#multiple 89.5% <67.74%> (+0.01%) ⬆️
#single 40.83% <29.03%> (-0.13%) ⬇️
Impacted Files Coverage Δ
pandas/core/ops.py 90.17% <67.74%> (-1.6%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/compat/numpy/function.py 88.48% <0%> (-3.64%) ⬇️
pandas/util/_test_decorators.py 92.06% <0%> (-2.49%) ⬇️
pandas/plotting/_converter.py 65.22% <0%> (-1.3%) ⬇️
pandas/io/sql.py 94.3% <0%> (-0.49%) ⬇️
pandas/io/common.py 69.06% <0%> (-0.43%) ⬇️
pandas/core/series.py 94.65% <0%> (-0.17%) ⬇️
pandas/core/dtypes/common.py 94.29% <0%> (-0.17%) ⬇️
pandas/core/frame.py 97.68% <0%> (-0.11%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6a7cc9...a3cab61. Read the comment docs.

@gfyoung gfyoung added Clean Internals Related to non-user accessible pandas implementation labels Dec 19, 2017
if ((self.is_integer_lhs or self.is_floating_lhs) and
self.is_timedelta_rhs):

if name not in ('__div__', '__truediv__', '__mul__', '__rmul__'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe factor this to a function to avoid duplication with above,

assert_can_operate() or somesuch

@@ -960,8 +960,44 @@ def test_timedelta64_ops_nat(self):
assert_series_equal(timedelta_series / nan,
nat_series_dtype_timedelta)

def test_operators_timedelta64_with_timedelta(self):
# smoke tests
td1 = Series([timedelta(minutes=5, seconds=3)] * 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we certainly have some of these, can you remove the existing ones if you are consolidating.

these also seem oddly specific, would parametrize on Timedelta, TDI as well here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we certainly have some of these, can you remove the existing ones if you are consolidating.

Yes, these are already moved out of the giant .test_operators_datetimelike

these also seem oddly specific, would parametrize on Timedelta, TDI as well here

Not sure about TDI, but definitely can parametrize over scalar timedelta variants.


def test_operators_timedelta64_with_timedelta_invalid(self):
td1 = Series([timedelta(minutes=5, seconds=3)] * 3)
td1.iloc[2] = np.nan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same parametization

@@ -976,16 +1012,6 @@ def run_ops(ops, get_ser, test_ser):
# ## timedelta64 ###
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this initialization code then used below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

return self._validate_datetime(lvalues, rvalues, name)
elif self.is_timedelta_lhs:
return self._validate_timedelta(name)
elif self.is_offset_lhs:
Copy link
Contributor

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).

@jreback jreback added this to the 0.23.0 milestone Dec 23, 2017
@jreback jreback merged commit cdebcf3 into pandas-dev:master Dec 23, 2017
@jreback
Copy link
Contributor

jreback commented Dec 23, 2017

thanks!

@jbrockmendel jbrockmendel deleted the validate_ops branch February 11, 2018 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants