-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
dispatch Series[datetime64] ops to DatetimeIndex #19024
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
212d75c
2e37861
375e924
aa0b3a3
89e1096
cbf81e8
4efb27a
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 |
---|---|---|
|
@@ -744,6 +744,13 @@ def wrapper(left, right, name=name, na_op=na_op): | |
return NotImplemented | ||
|
||
left, right = _align_method_SERIES(left, right) | ||
if is_datetime64_dtype(left) or is_datetime64tz_dtype(left): | ||
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. and until / unless you want to limit / remove _TimeOp (which is actually ok with me). then this doesn't belong here as I have commented before. You are welcome to put it in _TimeOp for now or rip out TimeOp. |
||
result = op(pd.DatetimeIndex(left), right) | ||
res_name = _get_series_op_result_name(left, right) | ||
result.name = res_name # needs to be overriden if None | ||
return construct_result(left, result, | ||
index=left.index, name=res_name, | ||
dtype=result.dtype) | ||
|
||
converted = _Op.get_op(left, right, name, na_op) | ||
|
||
|
@@ -754,31 +761,36 @@ def wrapper(left, right, name=name, na_op=na_op): | |
na_op = converted.na_op | ||
|
||
if isinstance(rvalues, ABCSeries): | ||
name = _maybe_match_name(left, rvalues) | ||
lvalues = getattr(lvalues, 'values', lvalues) | ||
rvalues = getattr(rvalues, 'values', rvalues) | ||
# _Op aligns left and right | ||
else: | ||
if isinstance(rvalues, pd.Index): | ||
name = _maybe_match_name(left, rvalues) | ||
else: | ||
name = left.name | ||
if (hasattr(lvalues, 'values') and | ||
not isinstance(lvalues, pd.DatetimeIndex)): | ||
lvalues = lvalues.values | ||
|
||
result = wrap_results(safe_na_op(lvalues, rvalues)) | ||
res_name = _get_series_op_result_name(left, right) | ||
return construct_result( | ||
left, | ||
result, | ||
index=left.index, | ||
name=name, | ||
name=res_name, | ||
dtype=dtype, | ||
) | ||
|
||
return wrapper | ||
|
||
|
||
def _get_series_op_result_name(left, right): | ||
# `left` is always a pd.Series | ||
if isinstance(right, (ABCSeries, pd.Index)): | ||
name = _maybe_match_name(left, right) | ||
else: | ||
name = left.name | ||
return name | ||
|
||
|
||
def _comp_method_OBJECT_ARRAY(op, x, y): | ||
if isinstance(y, list): | ||
y = construct_1d_object_array_from_listlike(y) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ def test_shift(self): | |
# incompat tz | ||
s2 = Series(date_range('2000-01-01 09:00:00', periods=5, | ||
tz='CET'), name='foo') | ||
pytest.raises(ValueError, lambda: s - s2) | ||
pytest.raises(TypeError, lambda: s - s2) | ||
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 in the whatsnew notes API changed section? 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 |
||
|
||
def test_shift2(self): | ||
ts = Series(np.random.randn(5), | ||
|
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.
looks like some text got duped in the last entry