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


Python dtypes.IntervalDtype方法代码示例

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


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

示例1: test_subtype_integer_errors

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_integer_errors(self):
        # float64 -> uint64 fails with negative values
        index = interval_range(-10.0, 10.0)
        dtype = IntervalDtype('uint64')
        with pytest.raises(ValueError):
            index.astype(dtype)

        # float64 -> integer-like fails with non-integer valued floats
        index = interval_range(0.0, 10.0, freq=0.25)
        dtype = IntervalDtype('int64')
        with pytest.raises(ValueError):
            index.astype(dtype)

        dtype = IntervalDtype('uint64')
        with pytest.raises(ValueError):
            index.astype(dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_astype.py

示例2: test_subtype_datetimelike

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_datetimelike(self):
        # datetime -> timedelta raises
        dtype = IntervalDtype('timedelta64[ns]')
        msg = 'Cannot convert .* to .*; subtypes are incompatible'

        index = interval_range(Timestamp('2018-01-01'), periods=10)
        with tm.assert_raises_regex(TypeError, msg):
            index.astype(dtype)

        index = interval_range(Timestamp('2018-01-01', tz='CET'), periods=10)
        with tm.assert_raises_regex(TypeError, msg):
            index.astype(dtype)

        # timedelta -> datetime raises
        dtype = IntervalDtype('datetime64[ns]')
        index = interval_range(Timedelta('0 days'), periods=10)
        with tm.assert_raises_regex(TypeError, msg):
            index.astype(dtype) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_astype.py

示例3: dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def dtype():
    return IntervalDtype() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_interval.py

示例4: test_constructor_dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_constructor_dtype(self, constructor, breaks, subtype):
        # GH 19262: conversion via dtype parameter
        expected_kwargs = self.get_kwargs_from_breaks(breaks.astype(subtype))
        expected = constructor(**expected_kwargs)

        result_kwargs = self.get_kwargs_from_breaks(breaks)
        iv_dtype = IntervalDtype(subtype)
        for dtype in (iv_dtype, str(iv_dtype)):
            result = constructor(dtype=dtype, **result_kwargs)
            tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_construction.py

示例5: test_generic_errors

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_generic_errors(self, constructor):
        # filler input data to be used when supplying invalid kwargs
        filler = self.get_kwargs_from_breaks(range(10))

        # invalid closed
        msg = "invalid option for 'closed': invalid"
        with pytest.raises(ValueError, match=msg):
            constructor(closed='invalid', **filler)

        # unsupported dtype
        msg = 'dtype must be an IntervalDtype, got int64'
        with pytest.raises(TypeError, match=msg):
            constructor(dtype='int64', **filler)

        # invalid dtype
        msg = "data type 'invalid' not understood"
        with pytest.raises(TypeError, match=msg):
            constructor(dtype='invalid', **filler)

        # no point in nesting periods in an IntervalIndex
        periods = period_range('2000-01-01', periods=10)
        periods_kwargs = self.get_kwargs_from_breaks(periods)
        msg = 'Period dtypes are not supported, use a PeriodIndex instead'
        with pytest.raises(ValueError, match=msg):
            constructor(**periods_kwargs)

        # decreasing values
        decreasing_kwargs = self.get_kwargs_from_breaks(range(10, -1, -1))
        msg = 'left side of interval must be <= right side'
        with pytest.raises(ValueError, match=msg):
            constructor(**decreasing_kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_construction.py

示例6: test_subtype_conversion

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_conversion(self, index, subtype):
        dtype = IntervalDtype(subtype)
        result = index.astype(dtype)
        expected = IntervalIndex.from_arrays(index.left.astype(subtype),
                                             index.right.astype(subtype),
                                             closed=index.closed)
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_astype.py

示例7: test_subtype_integer

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_integer(self, subtype_start, subtype_end):
        index = IntervalIndex.from_breaks(np.arange(100, dtype=subtype_start))
        dtype = IntervalDtype(subtype_end)
        result = index.astype(dtype)
        expected = IntervalIndex.from_arrays(index.left.astype(subtype_end),
                                             index.right.astype(subtype_end),
                                             closed=index.closed)
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_astype.py

示例8: test_subtype_datetimelike

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_datetimelike(self, index, subtype):
        dtype = IntervalDtype(subtype)
        msg = 'Cannot convert .* to .*; subtypes are incompatible'
        with pytest.raises(TypeError, match=msg):
            index.astype(dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_astype.py

示例9: test_subtype_float

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_float(self, index):
        dtype = IntervalDtype('float64')
        msg = 'Cannot convert .* to .*; subtypes are incompatible'
        with pytest.raises(TypeError, match=msg):
            index.astype(dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_astype.py

示例10: dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def dtype(self):
        return IntervalDtype(self.left.dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:interval.py

示例11: test_generic_errors

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_generic_errors(self, constructor):
        # filler input data to be used when supplying invalid kwargs
        filler = self.get_kwargs_from_breaks(range(10))

        # invalid closed
        msg = "invalid option for 'closed': invalid"
        with tm.assert_raises_regex(ValueError, msg):
            constructor(closed='invalid', **filler)

        # unsupported dtype
        msg = 'dtype must be an IntervalDtype, got int64'
        with tm.assert_raises_regex(TypeError, msg):
            constructor(dtype='int64', **filler)

        # invalid dtype
        msg = 'data type "invalid" not understood'
        with tm.assert_raises_regex(TypeError, msg):
            constructor(dtype='invalid', **filler)

        # no point in nesting periods in an IntervalIndex
        periods = period_range('2000-01-01', periods=10)
        periods_kwargs = self.get_kwargs_from_breaks(periods)
        msg = 'Period dtypes are not supported, use a PeriodIndex instead'
        with tm.assert_raises_regex(ValueError, msg):
            constructor(**periods_kwargs)

        # decreasing values
        decreasing_kwargs = self.get_kwargs_from_breaks(range(10, -1, -1))
        msg = 'left side of interval must be <= right side'
        with tm.assert_raises_regex(ValueError, msg):
            constructor(**decreasing_kwargs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:33,代码来源:test_construction.py

示例12: test_subtype_float

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import IntervalDtype [as 别名]
def test_subtype_float(self, index):
        dtype = IntervalDtype('float64')
        msg = 'Cannot convert .* to .*; subtypes are incompatible'
        with tm.assert_raises_regex(TypeError, msg):
            index.astype(dtype) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_astype.py


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