Skip to content

Commit 75a442f

Browse files
committed
TST: fix local timezone checking with .timestamp()
1 parent 63d73d9 commit 75a442f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

pandas/tests/scalar/test_timestamp.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1101,13 +1101,18 @@ def test_timestamp(self):
11011101

11021102
tsc = Timestamp('2014-10-11 11:00:01.12345678', tz='US/Central')
11031103
utsc = tsc.tz_convert('UTC')
1104+
11041105
# utsc is a different representation of the same time
11051106
assert tsc.timestamp() == utsc.timestamp()
11061107

11071108
if PY3:
1108-
# should agree with datetime.timestamp method
1109-
dt = ts.to_pydatetime()
1110-
assert dt.timestamp() == ts.timestamp()
1109+
1110+
# datetime.timestamp() converts in the local timezone
1111+
with tm.set_timezone('UTC'):
1112+
1113+
# should agree with datetime.timestamp method
1114+
dt = ts.to_pydatetime()
1115+
assert dt.timestamp() == ts.timestamp()
11111116

11121117

11131118
class TestTimestampNsOperations(object):

pandas/tests/tseries/test_timezones.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import pandas.util.testing as tm
1515
import pandas.tseries.offsets as offsets
16-
from pandas.compat import lrange, zip
16+
from pandas.compat import lrange, zip, PY3
1717
from pandas.core.indexes.datetimes import bdate_range, date_range
1818
from pandas.core.dtypes.dtypes import DatetimeTZDtype
1919
from pandas._libs import tslib
@@ -1278,16 +1278,22 @@ def test_replace_tzinfo(self):
12781278
result_dt = dt.replace(tzinfo=tzinfo)
12791279
result_pd = Timestamp(dt).replace(tzinfo=tzinfo)
12801280

1281-
if hasattr(result_dt, 'timestamp'): # New method in Py 3.3
1282-
assert result_dt.timestamp() == result_pd.timestamp()
1281+
if PY3:
1282+
# datetime.timestamp() converts in the local timezone
1283+
with tm.set_timezone('UTC'):
1284+
assert result_dt.timestamp() == result_pd.timestamp()
1285+
12831286
assert result_dt == result_pd
12841287
assert result_dt == result_pd.to_pydatetime()
12851288

12861289
result_dt = dt.replace(tzinfo=tzinfo).replace(tzinfo=None)
12871290
result_pd = Timestamp(dt).replace(tzinfo=tzinfo).replace(tzinfo=None)
12881291

1289-
if hasattr(result_dt, 'timestamp'): # New method in Py 3.3
1290-
assert result_dt.timestamp() == result_pd.timestamp()
1292+
if PY3:
1293+
# datetime.timestamp() converts in the local timezone
1294+
with tm.set_timezone('UTC'):
1295+
assert result_dt.timestamp() == result_pd.timestamp()
1296+
12911297
assert result_dt == result_pd
12921298
assert result_dt == result_pd.to_pydatetime()
12931299

0 commit comments

Comments
 (0)