本文整理汇总了Python中pandas.tseries.frequencies.infer_freq方法的典型用法代码示例。如果您正苦于以下问题:Python frequencies.infer_freq方法的具体用法?Python frequencies.infer_freq怎么用?Python frequencies.infer_freq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.frequencies
的用法示例。
在下文中一共展示了frequencies.infer_freq方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_tick
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def _check_tick(self, base_delta, code):
b = Timestamp(datetime.now())
for i in range(1, 5):
inc = base_delta * i
index = _dti([b + inc * j for j in range(3)])
if i > 1:
exp_freq = '%d%s' % (i, code)
else:
exp_freq = code
assert frequencies.infer_freq(index) == exp_freq
index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
3)])
assert frequencies.infer_freq(index) is None
index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
7])
assert frequencies.infer_freq(index) is None
示例2: test_raise_if_period_index
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_raise_if_period_index(self):
index = period_range(start="1/1/1990", periods=20, freq="M")
pytest.raises(TypeError, frequencies.infer_freq, index)
示例3: test_raise_if_too_few
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_raise_if_too_few(self):
index = _dti(['12/31/1998', '1/3/1999'])
pytest.raises(ValueError, frequencies.infer_freq, index)
示例4: test_business_daily
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_business_daily(self):
index = _dti(['01/01/1999', '1/4/1999', '1/5/1999'])
assert frequencies.infer_freq(index) == 'B'
示例5: test_business_daily_look_alike
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_business_daily_look_alike(self):
# GH 16624, do not infer 'B' when 'weekend' (2-day gap) in wrong place
index = _dti(['12/31/1998', '1/3/1999', '1/4/1999'])
assert frequencies.infer_freq(index) is None
示例6: test_day_corner
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_day_corner(self):
index = _dti(['1/1/2000', '1/2/2000', '1/3/2000'])
assert frequencies.infer_freq(index) == 'D'
示例7: test_fifth_week_of_month_infer
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_fifth_week_of_month_infer(self):
# Only attempts to infer up to WOM-4. See #9425
index = DatetimeIndex(["2014-03-31", "2014-06-30", "2015-03-30"])
assert frequencies.infer_freq(index) is None
示例8: test_week_of_month_fake
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_week_of_month_fake(self):
# All of these dates are on same day of week and are 4 or 5 weeks apart
index = DatetimeIndex(["2013-08-27", "2013-10-01", "2013-10-29",
"2013-11-26"])
assert frequencies.infer_freq(index) != 'WOM-4TUE'
示例9: _check_generated_range
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def _check_generated_range(self, start, freq):
freq = freq.upper()
gen = date_range(start, periods=7, freq=freq)
index = _dti(gen.values)
if not freq.startswith('Q-'):
assert frequencies.infer_freq(index) == gen.freqstr
else:
inf_freq = frequencies.infer_freq(index)
is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')
assert is_dec_range or is_nov_range or is_oct_range
gen = date_range(start, periods=5, freq=freq)
index = _dti(gen.values)
if not freq.startswith('Q-'):
assert frequencies.infer_freq(index) == gen.freqstr
else:
inf_freq = frequencies.infer_freq(index)
is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')
assert is_dec_range or is_nov_range or is_oct_range
示例10: test_non_datetimeindex2
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_non_datetimeindex2(self):
rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])
vals = rng.to_pydatetime()
result = frequencies.infer_freq(vals)
assert result == rng.inferred_freq
示例11: test_string_datetimelike_compat
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_string_datetimelike_compat(self):
# GH 6463
expected = frequencies.infer_freq(['2004-01', '2004-02', '2004-03',
'2004-04'])
result = frequencies.infer_freq(Index(['2004-01', '2004-02', '2004-03',
'2004-04']))
assert result == expected
示例12: test_series
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_series(self):
# GH6407
# inferring series
# invalid type of Series
for s in [Series(np.arange(10)), Series(np.arange(10.))]:
pytest.raises(TypeError, lambda: frequencies.infer_freq(s))
# a non-convertible string
pytest.raises(ValueError, lambda: frequencies.infer_freq(
Series(['foo', 'bar'])))
# cannot infer on PeriodIndex
for freq in [None, 'L']:
s = Series(period_range('2013', periods=10, freq=freq))
pytest.raises(TypeError, lambda: frequencies.infer_freq(s))
# DateTimeIndex
for freq in ['M', 'L', 'S']:
s = Series(date_range('20130101', periods=10, freq=freq))
inferred = frequencies.infer_freq(s)
assert inferred == freq
s = Series(date_range('20130101', '20130110'))
inferred = frequencies.infer_freq(s)
assert inferred == 'D'
示例13: inferred_freq
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def inferred_freq(self):
"""
Tryies to return a string representing a frequency guess,
generated by infer_freq. Returns None if it can't autodetect the
frequency.
"""
try:
return frequencies.infer_freq(self)
except ValueError:
return None
示例14: test_raise_if_period_index
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def test_raise_if_period_index(self):
index = PeriodIndex(start="1/1/1990", periods=20, freq="M")
pytest.raises(TypeError, frequencies.infer_freq, index)
示例15: inferred_freq
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import infer_freq [as 别名]
def inferred_freq(self):
"""
Tries to return a string representing a frequency guess,
generated by infer_freq. Returns None if it can't autodetect the
frequency.
"""
try:
return frequencies.infer_freq(self)
except ValueError:
return None