-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
TST: Continue collecting arithmetic tests #22559
Changes from all commits
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 |
---|---|---|
|
@@ -42,6 +42,30 @@ def test_operator_series_comparison_zerorank(self): | |
expected = 0.0 > pd.Series([1, 2, 3]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_df_numeric_cmp_dt64_raises(self): | ||
# GH#8932, GH#22163 | ||
ts = pd.Timestamp.now() | ||
df = pd.DataFrame({'x': range(5)}) | ||
with pytest.raises(TypeError): | ||
df > ts | ||
with pytest.raises(TypeError): | ||
df < ts | ||
with pytest.raises(TypeError): | ||
ts < df | ||
with pytest.raises(TypeError): | ||
ts > df | ||
|
||
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. can you add for tz as well (use the fixture) 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. Sure; follow-up. This PR is pretty specifically only-moving. |
||
assert not (df == ts).any().any() | ||
assert (df != ts).all().all() | ||
|
||
def test_compare_invalid(self): | ||
# GH#8058 | ||
# ops testing | ||
a = pd.Series(np.random.randn(5), name=0) | ||
b = pd.Series(np.random.randn(5)) | ||
b.name = pd.Timestamp('2000-01-01') | ||
tm.assert_series_equal(a / b, 1 / (b / a)) | ||
|
||
|
||
# ------------------------------------------------------------------ | ||
# Numeric dtypes Arithmetic with Timedelta Scalar | ||
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. are there timedelta tests that should be moved (ok for followup, just indicate) 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. Those should all be in test_arithmetic, which this PR moves to arithmetic.test_timedelta64 |
||
|
@@ -754,6 +778,51 @@ def check(series, other): | |
check(tser, 5) | ||
|
||
|
||
class TestUFuncCompat(object): | ||
@pytest.mark.parametrize('holder', [pd.Int64Index, pd.UInt64Index, | ||
pd.Float64Index, pd.Series]) | ||
def test_ufunc_coercions(self, holder): | ||
idx = holder([1, 2, 3, 4, 5], name='x') | ||
box = pd.Series if holder is pd.Series else pd.Index | ||
|
||
result = np.sqrt(idx) | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index(np.sqrt(np.array([1, 2, 3, 4, 5])), name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = np.divide(idx, 2.) | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
# _evaluate_numeric_binop | ||
result = idx + 2. | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index([3., 4., 5., 6., 7.], name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx - 2. | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index([-1., 0., 1., 2., 3.], name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx * 1. | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index([1., 2., 3., 4., 5.], name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx / 2. | ||
assert result.dtype == 'f8' and isinstance(result, box) | ||
exp = pd.Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
|
||
class TestObjectDtypeEquivalence(object): | ||
# Tests that arithmetic operations match operations executed elementwise | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,3 +180,36 @@ def test_series_with_dtype_radd_timedelta(self, dtype): | |
|
||
result = ser + pd.Timedelta('3 days') | ||
tm.assert_series_equal(result, expected) | ||
|
||
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. would move these to test_datetime64 (maybe rename that to test_datetime) 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. These are mixed-type; it's pretty specifically the object-dtyped Index/Series/Column that these tests are addressing. |
||
# TODO: cleanup & parametrize over box | ||
def test_mixed_timezone_series_ops_object(self): | ||
# GH#13043 | ||
ser = pd.Series([pd.Timestamp('2015-01-01', tz='US/Eastern'), | ||
pd.Timestamp('2015-01-01', tz='Asia/Tokyo')], | ||
name='xxx') | ||
assert ser.dtype == object | ||
|
||
exp = pd.Series([pd.Timestamp('2015-01-02', tz='US/Eastern'), | ||
pd.Timestamp('2015-01-02', tz='Asia/Tokyo')], | ||
name='xxx') | ||
tm.assert_series_equal(ser + pd.Timedelta('1 days'), exp) | ||
tm.assert_series_equal(pd.Timedelta('1 days') + ser, exp) | ||
|
||
# object series & object series | ||
ser2 = pd.Series([pd.Timestamp('2015-01-03', tz='US/Eastern'), | ||
pd.Timestamp('2015-01-05', tz='Asia/Tokyo')], | ||
name='xxx') | ||
assert ser2.dtype == object | ||
exp = pd.Series([pd.Timedelta('2 days'), pd.Timedelta('4 days')], | ||
name='xxx') | ||
tm.assert_series_equal(ser2 - ser, exp) | ||
tm.assert_series_equal(ser - ser2, -exp) | ||
|
||
ser = pd.Series([pd.Timedelta('01:00:00'), pd.Timedelta('02:00:00')], | ||
name='xxx', dtype=object) | ||
assert ser.dtype == object | ||
|
||
exp = pd.Series([pd.Timedelta('01:30:00'), pd.Timedelta('02:30:00')], | ||
name='xxx') | ||
tm.assert_series_equal(ser + pd.Timedelta('00:30:00'), exp) | ||
tm.assert_series_equal(pd.Timedelta('00:30:00') + ser, exp) |
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.
shouldn't these be in test_datetime64?
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.
No, this is specifically testing that the numeric-dtypes are correctly handling the presence of datetime64-dtype, not vice-versa.