本文整理汇总了Python中pandas.tseries.frequencies.is_subperiod方法的典型用法代码示例。如果您正苦于以下问题:Python frequencies.is_subperiod方法的具体用法?Python frequencies.is_subperiod怎么用?Python frequencies.is_subperiod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.frequencies
的用法示例。
在下文中一共展示了frequencies.is_subperiod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _maybe_resample
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _maybe_resample(series, ax, freq, plotf, kwargs):
ax_freq = _get_ax_freq(ax)
if ax_freq is not None and freq != ax_freq:
if frequencies.is_superperiod(freq, ax_freq): # upsample input
series = series.copy()
series.index = series.index.asfreq(ax_freq, how='s')
freq = ax_freq
elif _is_sup(freq, ax_freq): # one is weekly
how = kwargs.pop('how', 'last')
series = series.resample('D', how=how).dropna()
series = series.resample(ax_freq, how=how).dropna()
freq = ax_freq
elif frequencies.is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
_upsample_others(ax, freq, plotf, kwargs)
ax_freq = freq
else: # pragma: no cover
raise ValueError('Incompatible frequency conversion')
return freq, ax_freq, series
示例2: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def test_is_superperiod_subperiod():
# input validation
assert not (frequencies.is_superperiod(offsets.YearEnd(), None))
assert not (frequencies.is_subperiod(offsets.MonthEnd(), None))
assert not (frequencies.is_superperiod(None, offsets.YearEnd()))
assert not (frequencies.is_subperiod(None, offsets.MonthEnd()))
assert not (frequencies.is_superperiod(None, None))
assert not (frequencies.is_subperiod(None, None))
assert (frequencies.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert (frequencies.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert (frequencies.is_superperiod(offsets.Hour(), offsets.Minute()))
assert (frequencies.is_subperiod(offsets.Minute(), offsets.Hour()))
assert (frequencies.is_superperiod(offsets.Second(), offsets.Milli()))
assert (frequencies.is_subperiod(offsets.Milli(), offsets.Second()))
assert (frequencies.is_superperiod(offsets.Milli(), offsets.Micro()))
assert (frequencies.is_subperiod(offsets.Micro(), offsets.Milli()))
assert (frequencies.is_superperiod(offsets.Micro(), offsets.Nano()))
assert (frequencies.is_subperiod(offsets.Nano(), offsets.Micro()))
示例3: _maybe_resample
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _maybe_resample(series, ax, kwargs):
# resample against axes freq if necessary
freq, ax_freq = _get_freq(ax, series)
if freq is None: # pragma: no cover
raise ValueError('Cannot use dynamic axis without frequency info')
# Convert DatetimeIndex to PeriodIndex
if isinstance(series.index, DatetimeIndex):
series = series.to_period(freq=freq)
if ax_freq is not None and freq != ax_freq:
if frequencies.is_superperiod(freq, ax_freq): # upsample input
series = series.copy()
series.index = series.index.asfreq(ax_freq, how='s')
freq = ax_freq
elif _is_sup(freq, ax_freq): # one is weekly
how = kwargs.pop('how', 'last')
series = getattr(series.resample('D'), how)().dropna()
series = getattr(series.resample(ax_freq), how)().dropna()
freq = ax_freq
elif frequencies.is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
_upsample_others(ax, freq, kwargs)
ax_freq = freq
else: # pragma: no cover
raise ValueError('Incompatible frequency conversion')
return freq, series
示例4: _is_sub
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _is_sub(f1, f2):
return ((f1.startswith('W') and frequencies.is_subperiod('D', f2)) or
(f2.startswith('W') and frequencies.is_subperiod(f1, 'D')))
示例5: _downsample
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _downsample(self, how, **kwargs):
"""
Downsample the cython defined function
Parameters
----------
how : string / cython mapped function
**kwargs : kw args passed to how function
"""
# we may need to actually resample as if we are timestamps
if self.kind == 'timestamp':
return super(PeriodIndexResampler, self)._downsample(how, **kwargs)
how = self._is_cython_func(how) or how
ax = self.ax
if is_subperiod(ax.freq, self.freq):
# Downsampling
return self._groupby_and_aggregate(how, grouper=self.grouper)
elif is_superperiod(ax.freq, self.freq):
if how == 'ohlc':
# GH #13083
# upsampling to subperiods is handled as an asfreq, which works
# for pure aggregating/reducing methods
# OHLC reduces along the time dimension, but creates multiple
# values for each period -> handle by _groupby_and_aggregate()
return self._groupby_and_aggregate(how, grouper=self.grouper)
return self.asfreq()
elif ax.freq == self.freq:
return self.asfreq()
raise IncompatibleFrequency(
'Frequency {} cannot be resampled to {}, as they are not '
'sub or super periods'.format(ax.freq, self.freq))
示例6: _adjust_binner_for_upsample
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _adjust_binner_for_upsample(self, binner):
""" adjust our binner when upsampling """
ax = self.ax
if is_subperiod(ax.freq, self.freq):
# We are actually downsampling
# but are in the asfreq path
# GH 12926
if self.closed == 'right':
binner = binner[1:]
else:
binner = binner[:-1]
return binner
示例7: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def test_is_superperiod_subperiod():
assert(fmod.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert(fmod.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert(fmod.is_superperiod(offsets.Hour(), offsets.Minute()))
assert(fmod.is_subperiod(offsets.Minute(), offsets.Hour()))
示例8: _resample_periods
# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import is_subperiod [as 别名]
def _resample_periods(self, obj):
axlabels = obj._get_axis(self.axis)
if len(axlabels) == 0:
new_index = PeriodIndex(data=[], freq=self.freq)
return obj.reindex(new_index)
else:
start = axlabels[0].asfreq(self.freq, how=self.convention)
end = axlabels[-1].asfreq(self.freq, how='end')
new_index = period_range(start, end, freq=self.freq)
# Start vs. end of period
memb = axlabels.asfreq(self.freq, how=self.convention)
if is_subperiod(axlabels.freq, self.freq) or self.how is not None:
# Downsampling
rng = np.arange(memb.values[0], memb.values[-1] + 1)
bins = memb.searchsorted(rng, side='right')
grouper = BinGrouper(bins, new_index)
grouped = obj.groupby(grouper, axis=self.axis)
return grouped.aggregate(self._agg_method)
elif is_superperiod(axlabels.freq, self.freq):
# Get the fill indexer
indexer = memb.get_indexer(new_index, method=self.fill_method,
limit=self.limit)
return _take_new_index(obj, indexer, new_index, axis=self.axis)
else:
raise ValueError('Frequency %s cannot be resampled to %s'
% (axlabels.freq, self.freq))