dispatchers.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:eemeter 作者: openeemeter 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号