Python pandas.util.testing.set_timezone() Examples
The following are 23
code examples of pandas.util.testing.set_timezone().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.util.testing
, or try the search function
.
Example #1
Source File: test_unary_ops.py From twitter-stock-recommendation with MIT License | 6 votes |
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()
Example #2
Source File: test_unary_ops.py From recruit with Apache License 2.0 | 6 votes |
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()
Example #3
Source File: test_timezones.py From vnpy_crypto with MIT License | 6 votes |
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__
Example #4
Source File: test_timezones.py From twitter-stock-recommendation with MIT License | 6 votes |
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__
Example #5
Source File: test_unary_ops.py From vnpy_crypto with MIT License | 6 votes |
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()
Example #6
Source File: test_timezones.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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__
Example #7
Source File: test_timezones.py From recruit with Apache License 2.0 | 6 votes |
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__
Example #8
Source File: test_timezones.py From coffeegrindsize with MIT License | 6 votes |
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__
Example #9
Source File: test_unary_ops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: test_tools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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
Example #11
Source File: test_unary_ops.py From twitter-stock-recommendation with MIT License | 5 votes |
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()
Example #12
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #13
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #14
Source File: test_tools.py From coffeegrindsize with MIT License | 5 votes |
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
Example #15
Source File: test_tools.py From coffeegrindsize with MIT License | 5 votes |
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
Example #16
Source File: test_unary_ops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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()
Example #17
Source File: test_tools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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
Example #18
Source File: test_unary_ops.py From vnpy_crypto with MIT License | 5 votes |
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()
Example #19
Source File: test_tools.py From vnpy_crypto with MIT License | 5 votes |
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
Example #20
Source File: test_tools.py From vnpy_crypto with MIT License | 5 votes |
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
Example #21
Source File: test_unary_ops.py From recruit with Apache License 2.0 | 5 votes |
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()
Example #22
Source File: test_tools.py From recruit with Apache License 2.0 | 5 votes |
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
Example #23
Source File: test_tools.py From recruit with Apache License 2.0 | 5 votes |
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