本文整理汇总了Python中pandas.util.testing.set_timezone方法的典型用法代码示例。如果您正苦于以下问题:Python testing.set_timezone方法的具体用法?Python testing.set_timezone怎么用?Python testing.set_timezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.set_timezone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_normalize_tz_local
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import set_timezone [as 别名]
def test_normalize_tz_local(self, timezone):
# GH#13459
with tm.set_timezone(timezone):
rng = date_range('1/1/2000 9:30', periods=10, freq='D',
tz=tzlocal())
result = rng.normalize()
expected = date_range('1/1/2000', periods=10, freq='D',
tz=tzlocal())
tm.assert_index_equal(result, expected)
assert result.is_normalized
assert not rng.is_normalized
# ------------------------------------------------------------
# DatetimeIndex.__new__
示例2: test_timestamp
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import set_timezone [as 别名]
def test_timestamp(self):
# GH#17329
# tz-naive --> treat it as if it were UTC for purposes of timestamp()
ts = Timestamp.now()
uts = ts.replace(tzinfo=utc)
assert ts.timestamp() == uts.timestamp()
tsc = Timestamp('2014-10-11 11:00:01.12345678', tz='US/Central')
utsc = tsc.tz_convert('UTC')
# utsc is a different representation of the same time
assert tsc.timestamp() == utsc.timestamp()
if PY3:
# datetime.timestamp() converts in the local timezone
with tm.set_timezone('UTC'):
# should agree with datetime.timestamp method
dt = ts.to_pydatetime()
assert dt.timestamp() == ts.timestamp()
示例3: test_to_datetime_now
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import set_timezone [as 别名]
def test_to_datetime_now(self):
# See GH#18666
with tm.set_timezone('US/Eastern'):
npnow = np.datetime64('now').astype('datetime64[ns]')
pdnow = pd.to_datetime('now')
pdnow2 = pd.to_datetime(['now'])[0]
# These should all be equal with infinite perf; this gives
# a generous margin of 10 seconds
assert abs(pdnow.value - npnow.astype(np.int64)) < 1e10
assert abs(pdnow2.value - npnow.astype(np.int64)) < 1e10
assert pdnow.tzinfo is None
assert pdnow2.tzinfo is None
示例4: test_to_datetime_today
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import set_timezone [as 别名]
def test_to_datetime_today(self):
# See GH#18666
# Test with one timezone far ahead of UTC and another far behind, so
# one of these will _almost_ alawys be in a different day from UTC.
# Unfortunately this test between 12 and 1 AM Samoa time
# this both of these timezones _and_ UTC will all be in the same day,
# so this test will not detect the regression introduced in #18666.
with tm.set_timezone('Pacific/Auckland'): # 12-13 hours ahead of UTC
nptoday = np.datetime64('today')\
.astype('datetime64[ns]').astype(np.int64)
pdtoday = pd.to_datetime('today')
pdtoday2 = pd.to_datetime(['today'])[0]
tstoday = pd.Timestamp('today')
tstoday2 = pd.Timestamp.today()
# These should all be equal with infinite perf; this gives
# a generous margin of 10 seconds
assert abs(pdtoday.normalize().value - nptoday) < 1e10
assert abs(pdtoday2.normalize().value - nptoday) < 1e10
assert abs(pdtoday.value - tstoday.value) < 1e10
assert abs(pdtoday.value - tstoday2.value) < 1e10
assert pdtoday.tzinfo is None
assert pdtoday2.tzinfo is None
with tm.set_timezone('US/Samoa'): # 11 hours behind UTC
nptoday = np.datetime64('today')\
.astype('datetime64[ns]').astype(np.int64)
pdtoday = pd.to_datetime('today')
pdtoday2 = pd.to_datetime(['today'])[0]
# These should all be equal with infinite perf; this gives
# a generous margin of 10 seconds
assert abs(pdtoday.normalize().value - nptoday) < 1e10
assert abs(pdtoday2.normalize().value - nptoday) < 1e10
assert pdtoday.tzinfo is None
assert pdtoday2.tzinfo is None
示例5: test_replace_tzinfo
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import set_timezone [as 别名]
def test_replace_tzinfo(self):
# GH#15683
dt = datetime(2016, 3, 27, 1)
tzinfo = pytz.timezone('CET').localize(dt, is_dst=False).tzinfo
result_dt = dt.replace(tzinfo=tzinfo)
result_pd = Timestamp(dt).replace(tzinfo=tzinfo)
if PY3:
# datetime.timestamp() converts in the local timezone
with tm.set_timezone('UTC'):
assert result_dt.timestamp() == result_pd.timestamp()
assert result_dt == result_pd
assert result_dt == result_pd.to_pydatetime()
result_dt = dt.replace(tzinfo=tzinfo).replace(tzinfo=None)
result_pd = Timestamp(dt).replace(tzinfo=tzinfo).replace(tzinfo=None)
if PY3:
# datetime.timestamp() converts in the local timezone
with tm.set_timezone('UTC'):
assert result_dt.timestamp() == result_pd.timestamp()
assert result_dt == result_pd
assert result_dt == result_pd.to_pydatetime()