Skip to content

Commit 7c67d9c

Browse files
jbrockmendeljreback
authored andcommitted
Centralize m8[ns] Arithmetic Tests (#22118)
1 parent c272c52 commit 7c67d9c

File tree

3 files changed

+743
-431
lines changed

3 files changed

+743
-431
lines changed

pandas/tests/indexes/timedeltas/test_arithmetic.py

-72
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import operator
32

43
import pytest
54
import numpy as np
@@ -13,7 +12,6 @@
1312
Series,
1413
Timestamp, Timedelta)
1514
from pandas.errors import PerformanceWarning, NullFrequencyError
16-
from pandas.core import ops
1715

1816

1917
@pytest.fixture(params=[pd.offsets.Hour(2), timedelta(hours=2),
@@ -270,53 +268,6 @@ def test_tdi_floordiv_timedelta_scalar(self, scalar_td):
270268
class TestTimedeltaIndexArithmetic(object):
271269
# Addition and Subtraction Operations
272270

273-
# -------------------------------------------------------------
274-
# Invalid Operations
275-
276-
@pytest.mark.parametrize('other', [3.14, np.array([2.0, 3.0])])
277-
@pytest.mark.parametrize('op', [operator.add, ops.radd,
278-
operator.sub, ops.rsub])
279-
def test_tdi_add_sub_float(self, op, other):
280-
dti = DatetimeIndex(['2011-01-01', '2011-01-02'], freq='D')
281-
tdi = dti - dti.shift(1)
282-
with pytest.raises(TypeError):
283-
op(tdi, other)
284-
285-
def test_tdi_add_str_invalid(self):
286-
# GH 13624
287-
tdi = TimedeltaIndex(['1 day', '2 days'])
288-
289-
with pytest.raises(TypeError):
290-
tdi + 'a'
291-
with pytest.raises(TypeError):
292-
'a' + tdi
293-
294-
@pytest.mark.parametrize('freq', [None, 'H'])
295-
def test_tdi_sub_period(self, freq):
296-
# GH#13078
297-
# not supported, check TypeError
298-
p = pd.Period('2011-01-01', freq='D')
299-
300-
idx = pd.TimedeltaIndex(['1 hours', '2 hours'], freq=freq)
301-
302-
with pytest.raises(TypeError):
303-
idx - p
304-
305-
with pytest.raises(TypeError):
306-
p - idx
307-
308-
@pytest.mark.parametrize('op', [operator.add, ops.radd,
309-
operator.sub, ops.rsub])
310-
@pytest.mark.parametrize('pi_freq', ['D', 'W', 'Q', 'H'])
311-
@pytest.mark.parametrize('tdi_freq', [None, 'H'])
312-
def test_dti_sub_pi(self, tdi_freq, pi_freq, op):
313-
# GH#20049 subtracting PeriodIndex should raise TypeError
314-
tdi = pd.TimedeltaIndex(['1 hours', '2 hours'], freq=tdi_freq)
315-
dti = pd.Timestamp('2018-03-07 17:16:40') + tdi
316-
pi = dti.to_period(pi_freq)
317-
with pytest.raises(TypeError):
318-
op(dti, pi)
319-
320271
# -------------------------------------------------------------
321272
# TimedeltaIndex.shift is used by __add__/__sub__
322273

@@ -626,29 +577,6 @@ def test_tdi_isub_timedeltalike(self, delta):
626577
rng -= delta
627578
tm.assert_index_equal(rng, expected)
628579

629-
# -------------------------------------------------------------
630-
# Binary operations TimedeltaIndex and datetime-like
631-
632-
def test_tdi_sub_timestamp_raises(self):
633-
idx = TimedeltaIndex(['1 day', '2 day'])
634-
msg = "cannot subtract a datelike from a TimedeltaIndex"
635-
with tm.assert_raises_regex(TypeError, msg):
636-
idx - Timestamp('2011-01-01')
637-
638-
def test_tdi_add_timestamp(self):
639-
idx = TimedeltaIndex(['1 day', '2 day'])
640-
641-
result = idx + Timestamp('2011-01-01')
642-
expected = DatetimeIndex(['2011-01-02', '2011-01-03'])
643-
tm.assert_index_equal(result, expected)
644-
645-
def test_tdi_radd_timestamp(self):
646-
idx = TimedeltaIndex(['1 day', '2 day'])
647-
648-
result = Timestamp('2011-01-01') + idx
649-
expected = DatetimeIndex(['2011-01-02', '2011-01-03'])
650-
tm.assert_index_equal(result, expected)
651-
652580
# -------------------------------------------------------------
653581
# __add__/__sub__ with ndarray[datetime64] and ndarray[timedelta64]
654582

0 commit comments

Comments
 (0)