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

Tests for fixed issues in Series[datetime64] #19072

Merged
merged 4 commits into from
Jan 5, 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
43 changes: 43 additions & 0 deletions pandas/tests/series/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,18 @@ def test_sub_single_tz(self):
expected = Series([Timedelta('-2days')])
assert_series_equal(result, expected)

def test_dt64tz_series_sub_dtitz(self):
# GH#19071 subtracting tzaware DatetimeIndex from tzaware Series
# (with same tz) raises, fixed by #19024
dti = pd.date_range('1999-09-30', periods=10, tz='US/Pacific')
ser = pd.Series(dti)
expected = pd.Series(pd.TimedeltaIndex(['0days'] * 10))

res = dti - ser
tm.assert_series_equal(res, expected)
res = ser - dti
tm.assert_series_equal(res, expected)

def test_sub_datetime_compat(self):
# see gh-14088
s = Series([datetime(2016, 8, 23, 12, tzinfo=pytz.utc), pd.NaT])
Expand Down Expand Up @@ -1317,6 +1329,37 @@ def test_datetime64_ops_nat(self):
with pytest.raises(TypeError):
nat_series_dtype_timestamp / 1

def test_dt64series_arith_overflow(self):
# GH#12534, fixed by #19024
dt = pd.Timestamp('1700-01-31')
td = pd.Timedelta('20000 Days')
dti = pd.date_range('1949-09-30', freq='100Y', periods=4)
ser = pd.Series(dti)
with pytest.raises(OverflowError):
ser - dt
with pytest.raises(OverflowError):
dt - ser
with pytest.raises(OverflowError):
ser + td
with pytest.raises(OverflowError):
td + ser

ser.iloc[-1] = pd.NaT
expected = pd.Series(['2004-10-03', '2104-10-04', '2204-10-04', 'NaT'],
dtype='datetime64[ns]')
res = ser + td
tm.assert_series_equal(res, expected)
res = td + ser
tm.assert_series_equal(res, expected)

ser.iloc[1:] = pd.NaT
expected = pd.Series(['91279 Days', 'NaT', 'NaT', 'NaT'],
dtype='timedelta64[ns]')
res = ser - dt
tm.assert_series_equal(res, expected)
res = dt - ser
tm.assert_series_equal(res, -expected)


class TestSeriesOperators(TestData):
def test_op_method(self):
Expand Down