def test_date_range_timestamp_equiv_explicit_dateutil(self): from pandas._libs.tslibs.timezones import dateutil_gettz as gettz rng = date_range("20090415", "20090519", tz=gettz("US/Eastern")) stamp = rng[0] ts = Timestamp("20090415", tz=gettz("US/Eastern"), freq="D") assert ts == stamp
def test_date_range_timestamp_equiv_explicit_dateutil(self): from pandas._libs.tslibs.timezones import dateutil_gettz as gettz rng = date_range('20090415', '20090519', tz=gettz('US/Eastern')) stamp = rng[0] ts = Timestamp('20090415', tz=gettz('US/Eastern'), freq='D') assert ts == stamp
def test_getitem_setitem_datetime_tz_dateutil(): from dateutil.tz import tzutc from pandas._libs.tslibs.timezones import dateutil_gettz as gettz tz = (lambda x: tzutc() if x == "UTC" else gettz(x) ) # handle special case for utc in dateutil N = 50 # testing with timezone, GH #2785 rng = date_range("1/1/1990", periods=N, freq="H", tz="America/New_York") ts = Series(np.random.randn(N), index=rng) # also test Timestamp tz handling, GH #2789 result = ts.copy() result["1990-01-01 09:00:00+00:00"] = 0 result["1990-01-01 09:00:00+00:00"] = ts[4] tm.assert_series_equal(result, ts) result = ts.copy() result["1990-01-01 03:00:00-06:00"] = 0 result["1990-01-01 03:00:00-06:00"] = ts[4] tm.assert_series_equal(result, ts) # repeat with datetimes result = ts.copy() result[datetime(1990, 1, 1, 9, tzinfo=tz("UTC"))] = 0 result[datetime(1990, 1, 1, 9, tzinfo=tz("UTC"))] = ts[4] tm.assert_series_equal(result, ts) result = ts.copy() result[datetime(1990, 1, 1, 3, tzinfo=tz("America/Chicago"))] = 0 result[datetime(1990, 1, 1, 3, tzinfo=tz("America/Chicago"))] = ts[4] tm.assert_series_equal(result, ts)
def test_reindex_timestamp_with_fold(self, timezone, year, month, day, hour): # see gh-40817 test_timezone = gettz(timezone) transition_1 = pd.Timestamp( year=year, month=month, day=day, hour=hour, minute=0, fold=0, tzinfo=test_timezone, ) transition_2 = pd.Timestamp( year=year, month=month, day=day, hour=hour, minute=0, fold=1, tzinfo=test_timezone, ) df = ( DataFrame({"index": [transition_1, transition_2], "vals": ["a", "b"]}) .set_index("index") .reindex(["1", "2"]) ) tm.assert_frame_equal( df, DataFrame({"index": ["1", "2"], "vals": [None, None]}).set_index("index"), )
def test_hash_timestamp_with_fold(self, timezone, year, month, day, hour): # see gh-33931 test_timezone = gettz(timezone) transition_1 = Timestamp( year=year, month=month, day=day, hour=hour, minute=0, fold=0, tzinfo=test_timezone, ) transition_2 = Timestamp( year=year, month=month, day=day, hour=hour, minute=0, fold=1, tzinfo=test_timezone, ) assert hash(transition_1) == hash(transition_2)
def test_getitem_setitem_datetime_tz_dateutil(): from dateutil.tz import tzutc from pandas._libs.tslibs.timezones import dateutil_gettz as gettz tz = lambda x: tzutc() if x == 'UTC' else gettz( x) # handle special case for utc in dateutil from pandas import date_range N = 50 # testing with timezone, GH #2785 rng = date_range('1/1/1990', periods=N, freq='H', tz='America/New_York') ts = Series(np.random.randn(N), index=rng) # also test Timestamp tz handling, GH #2789 result = ts.copy() result["1990-01-01 09:00:00+00:00"] = 0 result["1990-01-01 09:00:00+00:00"] = ts[4] assert_series_equal(result, ts) result = ts.copy() result["1990-01-01 03:00:00-06:00"] = 0 result["1990-01-01 03:00:00-06:00"] = ts[4] assert_series_equal(result, ts) # repeat with datetimes result = ts.copy() result[datetime(1990, 1, 1, 9, tzinfo=tz('UTC'))] = 0 result[datetime(1990, 1, 1, 9, tzinfo=tz('UTC'))] = ts[4] assert_series_equal(result, ts) result = ts.copy() result[datetime(1990, 1, 1, 3, tzinfo=tz('America/Chicago'))] = 0 result[datetime(1990, 1, 1, 3, tzinfo=tz('America/Chicago'))] = ts[4] assert_series_equal(result, ts)
def test_timestamp_to_datetime_explicit_dateutil(self): stamp = Timestamp('20090415', tz=gettz('US/Eastern'), freq='D') dtval = stamp.to_pydatetime() assert stamp == dtval assert stamp.tzinfo == dtval.tzinfo
def test_timestamp_to_datetime_explicit_dateutil(self): stamp = Timestamp("20090415", tz=gettz("US/Eastern"), freq="D") dtval = stamp.to_pydatetime() assert stamp == dtval assert stamp.tzinfo == dtval.tzinfo