當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。