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: bare-bones fixture for timedelta array tests #23207

Merged
merged 3 commits into from
Oct 19, 2018
Merged
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
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