From b5e1fc21b7861cad53dbf025b6811a79f71c7c4f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 19 Oct 2018 06:00:46 -0700 Subject: [PATCH] TST: bare-bones fixture for timedelta array tests (#23207) --- pandas/tests/arrays/test_datetimelike.py | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index bfce5fb1462d9..a13eb8dec51d1 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -34,7 +34,7 @@ def datetime_index(request): A fixture to provide DatetimeIndex objects with different frequencies. Most DatetimeArray behavior is already tested in DatetimeIndex tests, - so here we just test that the DatetimeIndex behavior matches + so here we just test that the DatetimeArray behavior matches the DatetimeIndex behavior. """ freqstr = request.param @@ -45,6 +45,18 @@ def datetime_index(request): return pi +@pytest.fixture +def timedelta_index(request): + """ + A fixture to provide TimedeltaIndex objects with different frequencies. + Most TimedeltaArray behavior is already tested in TimedeltaIndex tests, + so here we just test that the TimedeltaArray behavior matches + the TimedeltaIndex behavior. + """ + # TODO: flesh this out + return pd.TimedeltaIndex(['1 Day', '3 Hours', 'NaT']) + + class TestDatetimeArray(object): def test_from_dti(self, tz_naive_fixture): @@ -122,6 +134,34 @@ def test_astype_object(self): assert asobj.dtype == 'O' assert list(asobj) == list(tdi) + def test_to_pytimedelta(self, timedelta_index): + tdi = timedelta_index + arr = TimedeltaArrayMixin(tdi) + + expected = tdi.to_pytimedelta() + result = arr.to_pytimedelta() + + tm.assert_numpy_array_equal(result, expected) + + def test_total_seconds(self, timedelta_index): + tdi = timedelta_index + arr = TimedeltaArrayMixin(tdi) + + expected = tdi.total_seconds() + result = arr.total_seconds() + + tm.assert_numpy_array_equal(result, expected.values) + + @pytest.mark.parametrize('propname', pd.TimedeltaIndex._field_ops) + def test_int_properties(self, timedelta_index, propname): + tdi = timedelta_index + arr = TimedeltaArrayMixin(tdi) + + result = getattr(arr, propname) + expected = np.array(getattr(tdi, propname), dtype=result.dtype) + + tm.assert_numpy_array_equal(result, expected) + class TestPeriodArray(object):