8000 TST: Tests and Helpers for Datetime/Period Arrays by jbrockmendel · Pull Request #23502 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

TST: Tests and Helpers for Datetime/Period Arrays #23502

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

Merged
merged 13 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update fixture name, add dtypes.generic tests
  • Loading branch information
jbrockmendel committed Nov 7, 2018
commit 87070a2d33fda8eb1c3816fa17bb1bff822a4b1d
1 change: 0 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def wrapper(self, other):
return ops.invalid_comparison(self, other, op)
else:
if isinstance(other, list):
# FIXME: This can break for object-dtype with mixed types
try:
other = type(self)(other)
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def box_with_period(request):

@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame, DatetimeArray],
ids=lambda x: x.__name__)
def box_with_dtarray(request):
def box_with_datetime(request):
"""
Like `box`, but specific to datetime64 for also testing DatetimeArray
"""
Expand Down
20 changes: 10 additions & 10 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@ def test_dti_add_sub_float(self, op, other):
with pytest.raises(TypeError):
op(dti, other)

def test_dti_add_timestamp_raises(self, box_with_dtarray):
def test_dti_add_timestamp_raises(self, box_with_datetime):
# GH#22163 ensure DataFrame doesn't cast Timestamp to i8
idx = DatetimeIndex(['2011-01-01', '2011-01-02'])
idx = tm.box_expected(idx, box_with_dtarray)
idx = tm.box_expected(idx, box_with_datetime)
msg = "cannot add"
with tm.assert_raises_regex(TypeError, msg):
idx + Timestamp('2011-01-01')
Expand Down Expand Up @@ -1153,16 +1153,16 @@ def test_dti_add_intarray_no_freq(self, box):
# Binary operations DatetimeIndex and timedelta-like

def test_dti_add_timedeltalike(self, tz_naive_fixture, two_hours,
box_with_dtarray):
box_with_datetime):
# GH#22005, GH#22163 check DataFrame doesn't raise TypeError
tz = tz_naive_fixture
rng = pd.date_range('2000-01-01', '2000-02-01', tz=tz)
rng = tm.box_expected(rng, box_with_dtarray)
rng = tm.box_expected(rng, box_with_datetime)

result = rng + two_hours
expected = pd.date_range('2000-01-01 02:00',
'2000-02-01 02:00', tz=tz)
expected = tm.box_expected(expected, box_with_dtarray)
expected = tm.box_expected(expected, box_with_datetime)
tm.assert_equal(result, expected)

def test_dti_iadd_timedeltalike(self, tz_naive_fixture, two_hours):
Expand Down Expand Up @@ -1432,13 +1432,13 @@ def test_sub_dti_dti(self):
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize('freq', [None, 'D'])
def test_sub_period(self, freq, box_with_dtarray):
def test_sub_period(self, freq, box_with_datetime):
# GH#13078
# not supported, check TypeError
p = pd.Period('2011-01-01', freq='D')

idx = pd.DatetimeIndex(['2011-01-01', '2011-01-02'], freq=freq)
idx = tm.box_expected(idx, box_with_dtarray)
idx = tm.box_expected(idx, box_with_datetime)

with pytest.raises(TypeError):
idx - p
Expand Down Expand Up @@ -1780,7 +1780,7 @@ def test_dti_with_offset_series(self, tz_naive_fixture, names):
res3 = dti - other
tm.assert_series_equal(res3, expected_sub)

def test_dti_add_offset_tzaware(self, tz_aware_fixture, box_with_dtarray):
def test_dti_add_offset_tzaware(self, tz_aware_fixture, box_with_datetime):
# GH#21610, GH#22163 ensure DataFrame doesn't return object-dtype
timezone = tz_aware_fixture
if timezone == 'US/Pacific':
Expand All @@ -1793,8 +1793,8 @@ def test_dti_add_offset_tzaware(self, tz_aware_fixture, box_with_dtarray):
expected = DatetimeIndex(['2010-11-01 05:00', '2010-11-01 06:00',
'2010-11-01 07:00'], freq='H', tz=timezone)

dates = tm.box_expected(dates, box_with_dtarray)
expected = tm.box_expected(expected, box_with_dtarray)
dates = tm.box_expected(dates, box_with_datetime)
expected = tm.box_expected(expected, box_with_datetime)

# TODO: parametrize over the scalar being added? radd? sub?
offset = dates + pd.offsets.Hour(5)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class TestABCClasses(object):
sparse_series = pd.Series([1, 2, 3]).to_sparse()
sparse_array = pd.SparseArray(np.random.randn(10))
sparse_frame = pd.SparseDataFrame({'a': [1, -1, None]})
datetime_array = pd.core.arrays.DatetimeArrayMixin(datetime_index)
timedelta_array = pd.core.arrays.TimedeltaArrayMixin(timedelta_index)

def test_abc_types(self):
assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex)
Expand Down Expand Up @@ -51,6 +53,12 @@ def test_abc_types(self):
assert isinstance(pd.Interval(0, 1.5), gt.ABCInterval)
assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCInterval)

assert isinstance(self.datetime_array, gt.ABCDatetimeArray)
assert not isinstance(self.datetime_index, gt.ABCDatetimeArray)

assert isinstance(self.timedelta_array, gt.ABCTimedeltaArray)
assert not isinstance(self.timedelta_index, gt.ABCTimedeltaArray)


def test_setattr_warnings():
# GH7175 - GOTCHA: You can't use dot notation to add a column...
Expand Down
0