|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| -import operator |
3 | 2 |
|
4 | 3 | import pytest
|
5 | 4 | import numpy as np
|
|
13 | 12 | Series,
|
14 | 13 | Timestamp, Timedelta)
|
15 | 14 | from pandas.errors import PerformanceWarning, NullFrequencyError
|
16 |
| -from pandas.core import ops |
17 | 15 |
|
18 | 16 |
|
19 | 17 | @pytest.fixture(params=[pd.offsets.Hour(2), timedelta(hours=2),
|
@@ -270,53 +268,6 @@ def test_tdi_floordiv_timedelta_scalar(self, scalar_td):
|
270 | 268 | class TestTimedeltaIndexArithmetic(object):
|
271 | 269 | # Addition and Subtraction Operations
|
272 | 270 |
|
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 |
| - |
320 | 271 | # -------------------------------------------------------------
|
321 | 272 | # TimedeltaIndex.shift is used by __add__/__sub__
|
322 | 273 |
|
@@ -626,29 +577,6 @@ def test_tdi_isub_timedeltalike(self, delta):
|
626 | 577 | rng -= delta
|
627 | 578 | tm.assert_index_equal(rng, expected)
|
628 | 579 |
|
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 |
| - |
652 | 580 | # -------------------------------------------------------------
|
653 | 581 | # __add__/__sub__ with ndarray[datetime64] and ndarray[timedelta64]
|
654 | 582 |
|
|
0 commit comments