-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Tests for TDI issues already fixed #19044
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
Changes from 3 commits
1cd1399
4d2333f
3b02815
0cd06e4
24062d0
d6a5752
bf09444
57f794b
6f7e5b2
10296e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4020,6 +4020,11 @@ def _add_numeric_methods_binary(cls): | |
|
||
def _make_evaluate_binop(op, opstr, reversed=False, constructor=Index): | ||
def _evaluate_numeric_binop(self, other): | ||
if (isinstance(other, ABCSeries) and | ||
self.dtype == "timedelta64[ns]"): | ||
# GH#19042 This needs to be changed for all Index classes, | ||
# but is only being handled for TimedeltaIndex in this PR. | ||
return NotImplemented | ||
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. Explain why you're doing this in a comment. 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. I'll expand the comment. This actually needs to be done for all Index classes because the problem is wide-spread, but I really want to avoid scope creep. 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. Fair enough. I agree that we should try to keep the scope well-defined, though I might consider adding tests that you can |
||
other = self._validate_for_numeric_binop(other, op, opstr) | ||
|
||
# handle time-based others | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -775,6 +775,12 @@ def wrapper(left, right, name=name, na_op=na_op): | |
res_name = left.name | ||
|
||
result = wrap_results(safe_na_op(lvalues, rvalues)) | ||
try: | ||
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. I would do this in _construct_result and simply pass in 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. Good call. |
||
# if res_name is None we may need to override `result.name` | ||
result.name = res_name | ||
except AttributeError: | ||
# np.ndarray has no name | ||
pass | ||
return construct_result( | ||
left, | ||
result, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,22 @@ def test_numeric_compat(self): | |
result = idx**2.0 | ||
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.xfail(reason="Index._add_numeric_methods_binary does not " | ||
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 there an issue number ? I don't actually like adding a lot of xfails, if its only 1 ok 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. Yah, 19042. I'm removing this test. |
||
"return NotImplemented when operating against " | ||
"a Series.") | ||
def test_index_with_series(self): | ||
# GH#19044 | ||
idx = self.create_index() | ||
didx = idx * idx | ||
arr_dtype = 'uint64' if isinstance(idx, UInt64Index) else 'int64' | ||
result = idx * Series(np.arange(5, dtype=arr_dtype)) | ||
tm.assert_series_equal(result, Series(didx)) | ||
|
||
result = idx * Series(np.arange(5, dtype='float64') + 0.1) | ||
expected = Series(Float64Index(np.arange(5, dtype='float64') * | ||
(np.arange(5, dtype='float64') + 0.1))) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_explicit_conversions(self): | ||
|
||
# GH 8608 | ||
|
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 don't like this at all. either let's remove this for now (and the corresponding test) or simplemente this by an override in the appopriate subclass.
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.
Removing this for now.
Overriding in subclass is a PITA b/c TimedeltaIndex._add_numeric_methods() is called below the definition of TimedeltaIndex and will override any
__mul__
or__div__
methods we put in the class itself. So to override we need to implement it outside the class and pin it on after the call to add_numeric_methods. Since this is among my least favorite patterns, I'm punting on it.