Skip to content

Commit

Permalink
TST: bare-bones fixture for timedelta array tests (pandas-dev#23207)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and tm9k1 committed Nov 19, 2018
1 parent 8137242 commit 2f60f1d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 2f60f1d

Please sign in to comment.