-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
dispatch scalar DataFrame ops to Series #22163
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 1 commit
7681092
b226abf
3fd46bc
0dff3a1
caf2da0
6ff8705
0513e0b
3a7b782
6636565
edc3792
3c65f93
2cdc58b
4703db7
c090713
d683cb3
8c64cf6
dbdea1a
f1edec4
9b62135
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -898,7 +898,6 @@ def test_timedelta_ops_with_missing_values(self): | |
scalar1 = pd.to_timedelta('00:00:01') | ||
scalar2 = pd.to_timedelta('00:00:02') | ||
timedelta_NaT = pd.to_timedelta('NaT') | ||
NA = np.nan | ||
|
||
actual = scalar1 + scalar1 | ||
assert actual == scalar2 | ||
|
@@ -966,10 +965,10 @@ def test_timedelta_ops_with_missing_values(self): | |
actual = df1 - timedelta_NaT | ||
tm.assert_frame_equal(actual, dfn) | ||
|
||
actual = df1 + NA | ||
tm.assert_frame_equal(actual, dfn) | ||
actual = df1 - NA | ||
tm.assert_frame_equal(actual, dfn) | ||
with pytest.raises(TypeError): | ||
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. why is this raising? this is a big change if you don't allow nan to act as NaT in ops 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. This is the current behavior for Series and Index. 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. this needs a subsection in the whatsnew then, marked as an api change. |
||
actual = df1 + np.nan | ||
with pytest.raises(TypeError): | ||
actual = df1 - np.nan | ||
|
||
actual = df1 + pd.NaT # NaT is datetime, not timedelta | ||
tm.assert_frame_equal(actual, dfn) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1235,16 +1235,31 @@ def test_binop_other(self, op, value, dtype): | |
(operator.truediv, 'bool'), | ||
(operator.mod, 'i8'), | ||
(operator.mod, 'complex128'), | ||
(operator.mod, '<M8[ns]'), | ||
(operator.mod, '<m8[ns]'), | ||
(operator.pow, 'bool')} | ||
if (op, dtype) in skip: | ||
pytest.skip("Invalid combination {},{}".format(op, dtype)) | ||
|
||
e = DummyElement(value, dtype) | ||
s = pd.DataFrame({"A": [e.value, e.value]}, dtype=e.dtype) | ||
result = op(s, e).dtypes | ||
expected = op(s, value).dtypes | ||
assert_series_equal(result, expected) | ||
|
||
invalid = {(operator.pow, '<M8[ns]'), | ||
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. pull this out and parametrize 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. This test already has two layers of parametrization; it isn't clear how to pull this out without making it more verbose+repetitive. Let me give this some thought and circle back. |
||
(operator.mod, '<M8[ns]'), | ||
(operator.truediv, '<M8[ns]'), | ||
(operator.mul, '<M8[ns]'), | ||
(operator.add, '<M8[ns]'), | ||
(operator.pow, '<m8[ns]'), | ||
(operator.mod, '<m8[ns]'), | ||
(operator.mul, '<m8[ns]')} | ||
|
||
if (op, dtype) in invalid: | ||
with pytest.raises(TypeError): | ||
result = op(s, e.value) | ||
else: | ||
# FIXME: Since dispatching to Series, this test no longer | ||
# asserts anything meaningful | ||
result = op(s, e.value).dtypes | ||
expected = op(s, value).dtypes | ||
assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('typestr, holder', [ | ||
|
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 is pretty annoything that we have to do this, I would make an explict function maybe
is_any_scalar
I think as we have these types of checks all over. pls make an issue for this.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.
Done.