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


Python timezones.maybe_get_tz方法代码示例

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


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

示例1: test_utc_box_timestamp_and_localize

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_utc_box_timestamp_and_localize(self, tzstr):
        tz = timezones.maybe_get_tz(tzstr)

        rng = date_range('3/11/2012', '3/12/2012', freq='H', tz='utc')
        rng_eastern = rng.tz_convert(tzstr)

        expected = rng[-1].astimezone(tz)

        stamp = rng_eastern[-1]
        assert stamp == expected
        assert stamp.tzinfo == expected.tzinfo

        # right tzinfo
        rng = date_range('3/13/2012', '3/14/2012', freq='H', tz='utc')
        rng_eastern = rng.tz_convert(tzstr)
        # test not valid for dateutil timezones.
        # assert 'EDT' in repr(rng_eastern[0].tzinfo)
        assert ('EDT' in repr(rng_eastern[0].tzinfo) or
                'tzfile' in repr(rng_eastern[0].tzinfo)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_timezones.py

示例2: test_range_tz_dateutil

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_range_tz_dateutil(self):
        # see gh-2906

        # Use maybe_get_tz to fix filename in tz under dateutil.
        from pandas._libs.tslibs.timezones import maybe_get_tz
        tz = lambda x: maybe_get_tz('dateutil/' + x)

        start = datetime(2011, 1, 1, tzinfo=tz('US/Eastern'))
        end = datetime(2011, 1, 3, tzinfo=tz('US/Eastern'))

        dr = date_range(start=start, periods=3)
        assert dr.tz == tz('US/Eastern')
        assert dr[0] == start
        assert dr[2] == end

        dr = date_range(end=end, periods=3)
        assert dr.tz == tz('US/Eastern')
        assert dr[0] == start
        assert dr[2] == end

        dr = date_range(start=start, end=end)
        assert dr.tz == tz('US/Eastern')
        assert dr[0] == start
        assert dr[2] == end 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_date_range.py

示例3: test_localized_at_time_between_time

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_localized_at_time_between_time(self, tzstr):
        from datetime import time
        tz = timezones.maybe_get_tz(tzstr)

        rng = date_range('4/16/2012', '5/1/2012', freq='H')
        ts = Series(np.random.randn(len(rng)), index=rng)

        ts_local = ts.tz_localize(tzstr)

        result = ts_local.at_time(time(10, 0))
        expected = ts.at_time(time(10, 0)).tz_localize(tzstr)
        tm.assert_series_equal(result, expected)
        assert timezones.tz_compare(result.index.tz, tz)

        t1, t2 = time(10, 0), time(11, 0)
        result = ts_local.between_time(t1, t2)
        expected = ts.between_time(t1, t2).tz_localize(tzstr)
        tm.assert_series_equal(result, expected)
        assert timezones.tz_compare(result.index.tz, tz) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_timezones.py

示例4: test_timestamp_tz_arg_dateutil

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_timestamp_tz_arg_dateutil(self):
        from pandas._libs.tslibs.timezones import dateutil_gettz
        from pandas._libs.tslibs.timezones import maybe_get_tz
        for case in ['dateutil/Europe/Brussels', 'dateutil/Asia/Tokyo',
                     'dateutil/US/Pacific']:
            p = Period('1/1/2005', freq='M').to_timestamp(
                tz=maybe_get_tz(case))
            exp = Timestamp('1/1/2005', tz='UTC').tz_convert(case)
            assert p == exp
            assert p.tz == dateutil_gettz(case.split('/', 1)[1])
            assert p.tz == exp.tz

            p = Period('1/1/2005',
                       freq='M').to_timestamp(freq='3H', tz=maybe_get_tz(case))
            exp = Timestamp('1/1/2005', tz='UTC').tz_convert(case)
            assert p == exp
            assert p.tz == dateutil_gettz(case.split('/', 1)[1])
            assert p.tz == exp.tz 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:20,代码来源:test_period.py

示例5: test_dti_tz_convert_utc_to_local_no_modify

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_dti_tz_convert_utc_to_local_no_modify(self, tz):
        rng = date_range('3/11/2012', '3/12/2012', freq='H', tz='utc')
        rng_eastern = rng.tz_convert(tz)

        # Values are unmodified
        tm.assert_numpy_array_equal(rng.asi8, rng_eastern.asi8)

        assert timezones.tz_compare(rng_eastern.tz, timezones.maybe_get_tz(tz)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_timezones.py

示例6: test_timetz_accessor

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_timetz_accessor(self, tz_naive_fixture):
        # GH21358
        tz = timezones.maybe_get_tz(tz_naive_fixture)

        expected = np.array([time(10, 20, 30, tzinfo=tz), pd.NaT])

        index = DatetimeIndex(['2018-06-04 10:20:30', pd.NaT], tz=tz)
        result = index.timetz

        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_timezones.py

示例7: test_date_range_timezone_str_argument

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_date_range_timezone_str_argument(self, tzstr):
        tz = timezones.maybe_get_tz(tzstr)
        result = date_range('1/1/2000', periods=10, tz=tzstr)
        expected = date_range('1/1/2000', periods=10, tz=tz)

        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_timezones.py

示例8: test_tzlocal_maybe_get_tz

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_tzlocal_maybe_get_tz():
    # see gh-13583
    tz = timezones.maybe_get_tz('tzlocal()')
    assert tz == dateutil.tz.tzlocal() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_timezones.py

示例9: test_tz_convert_corner

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_tz_convert_corner(arr):
    result = conversion.tz_convert(arr,
                                   timezones.maybe_get_tz("US/Eastern"),
                                   timezones.maybe_get_tz("Asia/Tokyo"))
    tm.assert_numpy_array_equal(result, arr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_conversion.py

示例10: test_series_tz_localize_empty

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_series_tz_localize_empty(self, tzstr):
        # GH#2248
        ser = Series()

        ser2 = ser.tz_localize('utc')
        assert ser2.index.tz == pytz.utc

        ser2 = ser.tz_localize(tzstr)
        timezones.tz_compare(ser2.index.tz, timezones.maybe_get_tz(tzstr))

    # -----------------------------------------------------------------
    # Series.tz_convert 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_timezones.py

示例11: test_getitem_pydatetime_tz

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_getitem_pydatetime_tz(self, tzstr):
        tz = timezones.maybe_get_tz(tzstr)

        index = date_range(start='2012-12-24 16:00', end='2012-12-24 18:00',
                           freq='H', tz=tzstr)
        ts = Series(index=index, data=index.hour)
        time_pandas = Timestamp('2012-12-24 17:00', tz=tzstr)

        dt = datetime(2012, 12, 24, 17, 0)
        time_datetime = conversion.localize_pydatetime(dt, tz)
        assert ts[time_pandas] == ts[time_datetime] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_timezones.py

示例12: test_tz_convert_utc_with_system_utc

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_tz_convert_utc_with_system_utc(self):
        from pandas._libs.tslibs.timezones import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())

    # ------------------------------------------------------------------
    # Timestamp.__init__ with tz str or tzinfo 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_timezones.py

示例13: test_timestamp_timetz_equivalent_with_datetime_tz

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_timestamp_timetz_equivalent_with_datetime_tz(self,
                                                          tz_naive_fixture):
        # GH21358
        tz = timezones.maybe_get_tz(tz_naive_fixture)

        stamp = Timestamp('2018-06-04 10:20:30', tz=tz)
        _datetime = datetime(2018, 6, 4, hour=10,
                             minute=20, second=30, tzinfo=tz)

        result = stamp.timetz()
        expected = _datetime.timetz()

        assert result == expected 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_timezones.py

示例14: test_to_timestamp_tz_arg_dateutil

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [as 别名]
def test_to_timestamp_tz_arg_dateutil(self, tzstr):
        tz = maybe_get_tz(tzstr)
        p = Period('1/1/2005', freq='M').to_timestamp(tz=tz)
        exp = Timestamp('1/1/2005', tz='UTC').tz_convert(tzstr)
        assert p == exp
        assert p.tz == dateutil_gettz(tzstr.split('/', 1)[1])
        assert p.tz == exp.tz

        p = Period('1/1/2005', freq='M').to_timestamp(freq='3H', tz=tz)
        exp = Timestamp('1/1/2005', tz='UTC').tz_convert(tzstr)
        assert p == exp
        assert p.tz == dateutil_gettz(tzstr.split('/', 1)[1])
        assert p.tz == exp.tz 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_period.py

示例15: _infer_tz_from_endpoints

# 需要导入模块: from pandas._libs.tslibs import timezones [as 别名]
# 或者: from pandas._libs.tslibs.timezones import maybe_get_tz [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.maybe_get_tz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。