当前位置: 首页>>代码示例>>Python>>正文


Python timezones.infer_tzinfo方法代码示例

本文整理汇总了Python中pandas._libs.tslibs.timezones.infer_tzinfo方法的典型用法代码示例。如果您正苦于以下问题:Python timezones.infer_tzinfo方法的具体用法?Python timezones.infer_tzinfo怎么用?Python timezones.infer_tzinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas._libs.tslibs.timezones的用法示例。


在下文中一共展示了timezones.infer_tzinfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_infer_tz

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def test_infer_tz(eastern, localize):
    utc = pytz.utc

    start_naive = datetime(2001, 1, 1)
    end_naive = datetime(2009, 1, 1)

    start = localize(eastern, start_naive)
    end = localize(eastern, end_naive)

    assert (timezones.infer_tzinfo(start, end) is
            tslib._localize_pydatetime(start_naive, eastern).tzinfo)
    assert (timezones.infer_tzinfo(start, None) is
            tslib._localize_pydatetime(start_naive, eastern).tzinfo)
    assert (timezones.infer_tzinfo(None, end) is
            tslib._localize_pydatetime(end_naive, eastern).tzinfo)

    start = utc.localize(start_naive)
    end = utc.localize(end_naive)
    assert timezones.infer_tzinfo(start, end) is utc

    end = tslib._localize_pydatetime(end_naive, eastern)
    with pytest.raises(Exception):
        timezones.infer_tzinfo(start, end)
    with pytest.raises(Exception):
        timezones.infer_tzinfo(end, start) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_timezones.py

示例2: test_infer_tz

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def test_infer_tz(self):
        eastern = self.tz('US/Eastern')
        utc = pytz.utc

        _start = datetime(2001, 1, 1)
        _end = datetime(2009, 1, 1)

        start = self.localize(eastern, _start)
        end = self.localize(eastern, _end)
        assert (timezones.infer_tzinfo(start, end) is
                self.localize(eastern, _start).tzinfo)
        assert (timezones.infer_tzinfo(start, None) is
                self.localize(eastern, _start).tzinfo)
        assert (timezones.infer_tzinfo(None, end) is
                self.localize(eastern, _end).tzinfo)

        start = utc.localize(_start)
        end = utc.localize(_end)
        assert (timezones.infer_tzinfo(start, end) is utc)

        end = self.localize(eastern, _end)
        pytest.raises(Exception, timezones.infer_tzinfo, start, end)
        pytest.raises(Exception, timezones.infer_tzinfo, end, start) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:25,代码来源:test_timezones.py

示例3: test_infer_tz_compat

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def test_infer_tz_compat(infer_setup):
    eastern, _, start, end, start_naive, end_naive = infer_setup

    assert (timezones.infer_tzinfo(start, end) is
            conversion.localize_pydatetime(start_naive, eastern).tzinfo)
    assert (timezones.infer_tzinfo(start, None) is
            conversion.localize_pydatetime(start_naive, eastern).tzinfo)
    assert (timezones.infer_tzinfo(None, end) is
            conversion.localize_pydatetime(end_naive, eastern).tzinfo) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_timezones.py

示例4: test_infer_tz_utc_localize

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def test_infer_tz_utc_localize(infer_setup):
    _, _, start, end, start_naive, end_naive = infer_setup
    utc = pytz.utc

    start = utc.localize(start_naive)
    end = utc.localize(end_naive)

    assert timezones.infer_tzinfo(start, end) is utc 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_timezones.py

示例5: test_infer_tz_mismatch

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def test_infer_tz_mismatch(infer_setup, ordered):
    eastern, _, _, _, start_naive, end_naive = infer_setup
    msg = "Inputs must both have the same timezone"

    utc = pytz.utc
    start = utc.localize(start_naive)
    end = conversion.localize_pydatetime(end_naive, eastern)

    args = (start, end) if ordered else (end, start)

    with pytest.raises(AssertionError, match=msg):
        timezones.infer_tzinfo(*args) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_timezones.py

示例6: _infer_tz_from_endpoints

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import infer_tzinfo [as 别名]
def _infer_tz_from_endpoints(start, end, tz):  # pragma: no cover
    """
    If a timezone is not explicitly given via `tz`, see if one can
    be inferred from the `start` and `end` endpoints.  If more than one
    of these inputs provides a timezone, require that they all agree.

    Parameters
    ----------
    start : Timestamp
    end : Timestamp
    tz : tzinfo or None

    Returns
    -------
    tz : tzinfo or None

    Raises
    ------
    TypeError : if start and end timezones do not agree
    """
    try:
        inferred_tz = timezones.infer_tzinfo(start, end)
    except AssertionError:
        # infer_tzinfo raises AssertionError if passed mismatched timezones
        raise TypeError(
            "Start and end cannot both be tz-aware with different timezones"
        )

    inferred_tz = timezones.maybe_get_tz(inferred_tz)
    tz = timezones.maybe_get_tz(tz)

    if tz is not None and inferred_tz is not None:
        if not timezones.tz_compare(inferred_tz, tz):
            raise AssertionError("Inferred time zone not equal to passed time zone")

    elif inferred_tz is not None:
        tz = inferred_tz

    return tz 
开发者ID:mars-project,项目名称:mars,代码行数:41,代码来源:date_range.py


注:本文中的pandas._libs.tslibs.timezones.infer_tzinfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。