Skip to content
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: parametrize and de-duplicate arithmetic tests #23240

Merged
merged 8 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,32 +323,35 @@ def test_dti_cmp_null_scalar_inequality(self, tz_naive_fixture, other):
with pytest.raises(TypeError):
dti >= other

def test_dti_cmp_nat(self):
@pytest.mark.parametrize('dtype', [None, object])
def test_dti_cmp_nat(self, dtype):
left = pd.DatetimeIndex([pd.Timestamp('2011-01-01'), pd.NaT,
pd.Timestamp('2011-01-03')])
right = pd.DatetimeIndex([pd.NaT, pd.NaT, pd.Timestamp('2011-01-03')])

for lhs, rhs in [(left, right),
(left.astype(object), right.astype(object))]:
result = rhs == lhs
expected = np.array([False, False, True])
tm.assert_numpy_array_equal(result, expected)
lhs, rhs = left, right
if dtype is object:
lhs, rhs = left.astype(object), right.astype(object)

result = rhs == lhs
expected = np.array([False, False, True])
tm.assert_numpy_array_equal(result, expected)

result = lhs != rhs
expected = np.array([True, True, False])
tm.assert_numpy_array_equal(result, expected)
result = lhs != rhs
expected = np.array([True, True, False])
tm.assert_numpy_array_equal(result, expected)

expected = np.array([False, False, False])
tm.assert_numpy_array_equal(lhs == pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT == rhs, expected)
expected = np.array([False, False, False])
tm.assert_numpy_array_equal(lhs == pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT == rhs, expected)

expected = np.array([True, True, True])
tm.assert_numpy_array_equal(lhs != pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT != lhs, expected)
expected = np.array([True, True, True])
tm.assert_numpy_array_equal(lhs != pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT != lhs, expected)

expected = np.array([False, False, False])
tm.assert_numpy_array_equal(lhs < pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT > lhs, expected)
expected = np.array([False, False, False])
tm.assert_numpy_array_equal(lhs < pd.NaT, expected)
tm.assert_numpy_array_equal(pd.NaT > lhs, expected)

def test_dti_cmp_nat_behaves_like_float_cmp_nan(self):
fidx1 = pd.Index([1.0, np.nan, 3.0, np.nan, 5.0, 7.0])
Expand Down Expand Up @@ -901,13 +904,15 @@ def test_dt64_series_add_intlike(self, tz, op):

other = Series([20, 30, 40], dtype='uint8')

pytest.raises(TypeError, getattr(ser, op), 1)

pytest.raises(TypeError, getattr(ser, op), other)

pytest.raises(TypeError, getattr(ser, op), other.values)

pytest.raises(TypeError, getattr(ser, op), pd.Index(other))
method = getattr(ser, op)
with pytest.raises(TypeError):
method(1)
with pytest.raises(TypeError):
method(other)
with pytest.raises(TypeError):
method(other.values)
with pytest.raises(TypeError):
method(pd.Index(other))

# -------------------------------------------------------------
# Timezone-Centric Tests
Expand Down Expand Up @@ -994,10 +999,6 @@ def test_dti_add_timestamp_raises(self, box):
msg = "cannot add"
with tm.assert_raises_regex(TypeError, msg):
idx + Timestamp('2011-01-01')

def test_dti_radd_timestamp_raises(self):
idx = DatetimeIndex(['2011-01-01', '2011-01-02'])
msg = "cannot add DatetimeIndex and Timestamp"
with tm.assert_raises_regex(TypeError, msg):
Timestamp('2011-01-01') + idx
Copy link
Member Author

Choose a reason for hiding this comment

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

Decided that separating tests for __add__ vs __radd__ was overkill.


Expand Down
Loading