本文整理汇总了Python中pandas.tseries.offsets.Day方法的典型用法代码示例。如果您正苦于以下问题:Python offsets.Day方法的具体用法?Python offsets.Day怎么用?Python offsets.Day使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.offsets
的用法示例。
在下文中一共展示了offsets.Day方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_with_local_timezone_pytz
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_with_local_timezone_pytz(self):
# see gh-5430
local_timezone = pytz.timezone('America/Los_Angeles')
start = datetime(year=2013, month=11, day=1, hour=0, minute=0,
tzinfo=pytz.utc)
# 1 day later
end = datetime(year=2013, month=11, day=2, hour=0, minute=0,
tzinfo=pytz.utc)
index = pd.date_range(start, end, freq='H')
series = Series(1, index=index)
series = series.tz_convert(local_timezone)
result = series.resample('D', kind='period').mean()
# Create the expected series
# Index is moved back a day with the timezone conversion from UTC to
# Pacific
expected_index = (pd.period_range(start=start, end=end, freq='D') -
offsets.Day())
expected = Series(1, index=expected_index)
assert_series_equal(result, expected)
示例2: test_roll_date_object
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_roll_date_object(self):
offset = BDay()
dt = date(2012, 9, 15)
result = offset.rollback(dt)
assert result == datetime(2012, 9, 14)
result = offset.rollforward(dt)
assert result == datetime(2012, 9, 17)
offset = offsets.Day()
result = offset.rollback(dt)
assert result == datetime(2012, 9, 15)
result = offset.rollforward(dt)
assert result == datetime(2012, 9, 15)
示例3: test_with_local_timezone_dateutil
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_with_local_timezone_dateutil(self):
# see gh-5430
local_timezone = 'dateutil/America/Los_Angeles'
start = datetime(year=2013, month=11, day=1, hour=0, minute=0,
tzinfo=dateutil.tz.tzutc())
# 1 day later
end = datetime(year=2013, month=11, day=2, hour=0, minute=0,
tzinfo=dateutil.tz.tzutc())
index = pd.date_range(start, end, freq='H', name='idx')
series = Series(1, index=index)
series = series.tz_convert(local_timezone)
result = series.resample('D', kind='period').mean()
# Create the expected series
# Index is moved back a day with the timezone conversion from UTC to
# Pacific
expected_index = (pd.period_range(start=start, end=end, freq='D',
name='idx') - offsets.Day())
expected = Series(1, index=expected_index)
assert_series_equal(result, expected)
示例4: compare_series_ts
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def compare_series_ts(result, expected, typ, version):
# GH 7748
tm.assert_series_equal(result, expected)
assert result.index.freq == expected.index.freq
assert not result.index.freq.normalize
tm.assert_series_equal(result > 0, expected > 0)
# GH 9291
freq = result.index.freq
assert freq + Day(1) == Day(2)
res = freq + pd.Timedelta(hours=1)
assert isinstance(res, pd.Timedelta)
assert res == pd.Timedelta(days=1, hours=1)
res = freq + pd.Timedelta(nanoseconds=1)
assert isinstance(res, pd.Timedelta)
assert res == pd.Timedelta(days=1, nanoseconds=1)
示例5: compare_series_ts
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def compare_series_ts(result, expected, typ, version):
# GH 7748
tm.assert_series_equal(result, expected)
assert result.index.freq == expected.index.freq
assert not result.index.freq.normalize
tm.assert_series_equal(result > 0, expected > 0)
# GH 9291
freq = result.index.freq
assert freq + Day(1) == Day(2)
res = freq + pandas.Timedelta(hours=1)
assert isinstance(res, pandas.Timedelta)
assert res == pandas.Timedelta(days=1, hours=1)
res = freq + pandas.Timedelta(nanoseconds=1)
assert isinstance(res, pandas.Timedelta)
assert res == pandas.Timedelta(days=1, nanoseconds=1)
示例6: test_roll_date_object
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_roll_date_object(self):
offset = BDay()
dt = date(2012, 9, 15)
result = offset.rollback(dt)
self.assertEqual(result, datetime(2012, 9, 14))
result = offset.rollforward(dt)
self.assertEqual(result, datetime(2012, 9, 17))
offset = offsets.Day()
result = offset.rollback(dt)
self.assertEqual(result, datetime(2012, 9, 15))
result = offset.rollforward(dt)
self.assertEqual(result, datetime(2012, 9, 15))
示例7: european_labour_day
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def european_labour_day(start_date=None,
end_date=None,
observance=None,
days_of_week=None):
return Holiday(
"Labour Day",
month=5,
day=1,
start_date=start_date,
end_date=end_date,
observance=observance,
days_of_week=days_of_week,
)
# Holy Wednesday, Maundy Thursday, Ascension Day, Whit Monday, and Corpus
# Christi do not take observance as a parameter because they depend on a
# particular offset, and offset and observance cannot both be passed to a
# Holiday.
示例8: chinese_national_day
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def chinese_national_day(start_date=None, end_date=None, observance=None):
return Holiday(
"Chinese National Day",
month=10,
day=1,
start_date=start_date,
end_date=end_date,
observance=observance,
)
# Precomputed Chinese Lunar Year dates.
#
# See Also
# --------
# trading_calendars/etc/lunisolar chinese-new-year
示例9: test_timedelta_range
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_timedelta_range(self):
expected = to_timedelta(np.arange(5), unit='D')
result = timedelta_range('0 days', periods=5, freq='D')
tm.assert_index_equal(result, expected)
expected = to_timedelta(np.arange(11), unit='D')
result = timedelta_range('0 days', '10 days', freq='D')
tm.assert_index_equal(result, expected)
expected = to_timedelta(np.arange(5), unit='D') + Second(2) + Day()
result = timedelta_range('1 days, 00:00:02', '5 days, 00:00:02',
freq='D')
tm.assert_index_equal(result, expected)
expected = to_timedelta([1, 3, 5, 7, 9], unit='D') + Second(2)
result = timedelta_range('1 days, 00:00:02', periods=5, freq='2D')
tm.assert_index_equal(result, expected)
expected = to_timedelta(np.arange(50), unit='T') * 30
result = timedelta_range('0 days', freq='30T', periods=50)
tm.assert_index_equal(result, expected)
# GH 11776
arr = np.arange(10).reshape(2, 5)
df = pd.DataFrame(np.arange(10).reshape(2, 5))
for arg in (arr, df):
with pytest.raises(TypeError, match="1-d array"):
to_timedelta(arg)
for errors in ['ignore', 'raise', 'coerce']:
with pytest.raises(TypeError, match="1-d array"):
to_timedelta(arg, errors=errors)
# issue10583
df = pd.DataFrame(np.random.normal(size=(10, 4)))
df.index = pd.timedelta_range(start='0s', periods=10, freq='s')
expected = df.loc[pd.Timedelta('0s'):, :]
result = df.loc['0s':, :]
tm.assert_frame_equal(expected, result)
示例10: test_constructor_coverage
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_constructor_coverage(self):
# float value for periods
expected = interval_range(start=0, periods=10)
result = interval_range(start=0, periods=10.5)
tm.assert_index_equal(result, expected)
# equivalent timestamp-like start/end
start, end = Timestamp('2017-01-01'), Timestamp('2017-01-15')
expected = interval_range(start=start, end=end)
result = interval_range(start=start.to_pydatetime(),
end=end.to_pydatetime())
tm.assert_index_equal(result, expected)
result = interval_range(start=start.asm8, end=end.asm8)
tm.assert_index_equal(result, expected)
# equivalent freq with timestamp
equiv_freq = ['D', Day(), Timedelta(days=1), timedelta(days=1),
DateOffset(days=1)]
for freq in equiv_freq:
result = interval_range(start=start, end=end, freq=freq)
tm.assert_index_equal(result, expected)
# equivalent timedelta-like start/end
start, end = Timedelta(days=1), Timedelta(days=10)
expected = interval_range(start=start, end=end)
result = interval_range(start=start.to_pytimedelta(),
end=end.to_pytimedelta())
tm.assert_index_equal(result, expected)
result = interval_range(start=start.asm8, end=end.asm8)
tm.assert_index_equal(result, expected)
# equivalent freq with timedelta
equiv_freq = ['D', Day(), Timedelta(days=1), timedelta(days=1)]
for freq in equiv_freq:
result = interval_range(start=start, end=end, freq=freq)
tm.assert_index_equal(result, expected)
示例11: test_qcut_nat
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_qcut_nat(ser):
# see gh-19768
intervals = IntervalIndex.from_tuples([
(ser[0] - Nano(), ser[2] - Day()),
np.nan, (ser[2] - Day(), ser[2])])
expected = Series(Categorical(intervals, ordered=True))
result = qcut(ser, 2)
tm.assert_series_equal(result, expected)
示例12: test_pickle_v0_15_2
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_pickle_v0_15_2(self, datapath):
offsets = {'DateOffset': DateOffset(years=1),
'MonthBegin': MonthBegin(1),
'Day': Day(1),
'YearBegin': YearBegin(1),
'Week': Week(1)}
pickle_path = datapath('tseries', 'offsets', 'data',
'dateoffset_0_15_2.pickle')
# This code was executed once on v0.15.2 to generate the pickle:
# with open(pickle_path, 'wb') as f: pickle.dump(offsets, f)
#
tm.assert_dict_equal(offsets, read_pickle(pickle_path))
示例13: test_corner
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_corner(self):
with pytest.raises(ValueError):
Week(weekday=7)
with pytest.raises(ValueError, match="Day must be"):
Week(weekday=-1)
示例14: test_constructor
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_constructor(self):
with pytest.raises(ValueError, match="^Week"):
WeekOfMonth(n=1, week=4, weekday=0)
with pytest.raises(ValueError, match="^Week"):
WeekOfMonth(n=1, week=-1, weekday=0)
with pytest.raises(ValueError, match="^Day"):
WeekOfMonth(n=1, week=0, weekday=-1)
with pytest.raises(ValueError, match="^Day"):
WeekOfMonth(n=1, week=0, weekday=-7)
示例15: test_delta_to_tick
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Day [as 别名]
def test_delta_to_tick():
delta = timedelta(3)
tick = offsets._delta_to_tick(delta)
assert (tick == offsets.Day(3))
td = Timedelta(nanoseconds=5)
tick = offsets._delta_to_tick(td)
assert tick == Nano(5)