def get_approximate_frequency(trace):
if trace.data is None:
logger.warn(
"Could not determine frequency:"
" {} is placeholder instance."
.format(trace)
)
return None
def _log_success(freq):
logger.debug(
"Determined frequency of '{}' for {}."
.format(freq, trace)
)
try:
freq = pd.infer_freq(trace.data.index)
except ValueError: # too few data points
logger.error("Could not determine frequency - too few points.")
return None
else:
if freq is not None:
_log_success(freq)
return freq
# freq is None - maybe because of a DST change (23/25 hours)?
# strategy: try two groups of 5 dates
for i in range(0, 9, 5):
try:
freq = pd.infer_freq(trace.data.index[i:i + 5])
except ValueError:
pass
else:
if freq is not None:
_log_success(freq)
return freq
logger.warning("Could not determine frequency - no dominant frequency.")
return None
评论列表
文章目录