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


Python DatetimeTZDtype.construct_from_string方法代码示例

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


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

示例1: test_construct_from_string_raises

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
    def test_construct_from_string_raises(self):
        with pytest.raises(TypeError, match="notatz"):
            DatetimeTZDtype.construct_from_string('datetime64[ns, notatz]')

        with pytest.raises(TypeError,
                           match="^Could not construct DatetimeTZDtype$"):
            DatetimeTZDtype.construct_from_string(['datetime64[ns, notatz]'])
开发者ID:johnnychiuchiu,项目名称:pandas,代码行数:9,代码来源:test_dtypes.py

示例2: test_construction_from_string

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
 def test_construction_from_string(self):
     result = DatetimeTZDtype.construct_from_string(
         'datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     msg = "Could not construct DatetimeTZDtype from 'foo'"
     with pytest.raises(TypeError, match=msg):
         DatetimeTZDtype.construct_from_string('foo')
开发者ID:chrish42,项目名称:pandas,代码行数:9,代码来源:test_dtypes.py

示例3: test_construction_from_string

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
 def test_construction_from_string(self):
     result = DatetimeTZDtype('datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     result = DatetimeTZDtype.construct_from_string(
         'datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     pytest.raises(TypeError,
                   lambda: DatetimeTZDtype.construct_from_string('foo'))
开发者ID:mficek,项目名称:pandas,代码行数:10,代码来源:test_dtypes.py

示例4: validate_tz_from_dtype

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
def validate_tz_from_dtype(dtype, tz):
    """
    If the given dtype is a DatetimeTZDtype, extract the implied
    tzinfo object from it and check that it does not conflict with the given
    tz.

    Parameters
    ----------
    dtype : dtype, str
    tz : None, tzinfo

    Returns
    -------
    tz : consensus tzinfo

    Raises
    ------
    ValueError : on tzinfo mismatch
    """
    if dtype is not None:
        try:
            dtype = DatetimeTZDtype.construct_from_string(dtype)
            dtz = getattr(dtype, 'tz', None)
            if dtz is not None:
                if tz is not None and not timezones.tz_compare(tz, dtz):
                    raise ValueError("cannot supply both a tz and a dtype"
                                     " with a tz")
                tz = dtz
        except TypeError:
            pass
    return tz
开发者ID:glyg,项目名称:pandas,代码行数:33,代码来源:datetimelike.py

示例5: test_parser

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
 def test_parser(self, tz, constructor):
     # pr #11245
     dtz_str = '{con}[ns, {tz}]'.format(con=constructor, tz=tz)
     result = DatetimeTZDtype.construct_from_string(dtz_str)
     expected = DatetimeTZDtype('ns', tz)
     assert result == expected
开发者ID:changhiskhan,项目名称:pandas,代码行数:8,代码来源:test_dtypes.py

示例6: test_subclass

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
    def test_subclass(self):
        a = DatetimeTZDtype.construct_from_string('datetime64[ns, US/Eastern]')
        b = DatetimeTZDtype.construct_from_string('datetime64[ns, CET]')

        assert issubclass(type(a), type(a))
        assert issubclass(type(a), type(b))
开发者ID:changhiskhan,项目名称:pandas,代码行数:8,代码来源:test_dtypes.py

示例7: test_datetimetz_dtype

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
 def test_datetimetz_dtype(self, dtype):
     assert (com.pandas_dtype(dtype) ==
             DatetimeTZDtype.construct_from_string(dtype))
     assert com.pandas_dtype(dtype) == dtype
开发者ID:clham,项目名称:pandas,代码行数:6,代码来源:test_common.py

示例8: assert

# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
    assert (not array_equivalent(m, n, strict_nan=False))


def test_array_equivalent_str():
    for dtype in ['O', 'S', 'U']:
        assert array_equivalent(np.array(['A', 'B'], dtype=dtype),
                                np.array(['A', 'B'], dtype=dtype))
        assert not array_equivalent(np.array(['A', 'B'], dtype=dtype),
                                    np.array(['A', 'X'], dtype=dtype))


@pytest.mark.parametrize('dtype, na_value', [
    # Datetime-like
    (np.dtype("M8[ns]"), NaT),
    (np.dtype("m8[ns]"), NaT),
    (DatetimeTZDtype.construct_from_string('datetime64[ns, US/Eastern]'), NaT),
    (PeriodDtype("M"), NaT),
    # Integer
    ('u1', 0), ('u2', 0), ('u4', 0), ('u8', 0),
    ('i1', 0), ('i2', 0), ('i4', 0), ('i8', 0),
    # Bool
    ('bool', False),
    # Float
    ('f2', np.nan), ('f4', np.nan), ('f8', np.nan),
    # Object
    ('O', np.nan),
    # Interval
    (IntervalDtype(), np.nan),
])
def test_na_value_for_dtype(dtype, na_value):
    result = na_value_for_dtype(dtype)
开发者ID:brianholland,项目名称:pandas,代码行数:33,代码来源:test_missing.py


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