Skip to content

TST: Add test case for GH14080 for overflow exception #23762

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 4 commits into from
Nov 18, 2018
Merged
Changes from 3 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
30 changes: 29 additions & 1 deletion pandas/tests/scalar/timestamp/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import pandas.util.testing as tm
from pandas.compat import long
from pandas.tseries import offsets
from pandas.tseries.frequencies import to_offset
from pandas import Timestamp, Timedelta


class TestTimestampArithmetic(object):
def test_overflow_offset(self):
def test_overflow_offset1(self):
# xref https://github.com/statsmodels/statsmodels/issues/3374
# ends up multiplying really large numbers which overflow

Expand All @@ -27,6 +28,33 @@ def test_overflow_offset(self):
with pytest.raises(OverflowError):
stamp - offset

def test_overflow_offset2(self):
# xref https://github.com/pandas-dev/pandas/issues/14080
# used to crash, so check for proper overflow exception

stamp = Timestamp("2000/1/1")
offset_overflow = to_offset("D") * 100 ** 25
offset_no_overflow = to_offset("D") * 100

# overflow expected
with pytest.raises(OverflowError):
stamp + offset_overflow

with pytest.raises(OverflowError):
offset_overflow + stamp

with pytest.raises(OverflowError):
stamp - offset_overflow

# no overflow expected
expected = Timestamp("2000/04/10")
assert stamp + offset_no_overflow == expected

assert offset_no_overflow + stamp == expected

expected = Timestamp("1999/09/23")
assert stamp - offset_no_overflow == expected

def test_delta_preserve_nanos(self):
val = Timestamp(long(1337299200000000123))
result = val + timedelta(1)
Expand Down