本文整理汇总了Python中pandas.core.dtypes.dtypes.IntervalDtype类的典型用法代码示例。如果您正苦于以下问题:Python IntervalDtype类的具体用法?Python IntervalDtype怎么用?Python IntervalDtype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalDtype类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_construction_from_string_errors
def test_construction_from_string_errors(self, string):
if isinstance(string, string_types):
error, msg = ValueError, 'could not construct IntervalDtype'
else:
error, msg = TypeError, 'a string needs to be passed, got type'
with tm.assert_raises_regex(error, msg):
IntervalDtype.construct_from_string(string)
示例2: test_construction_from_string_error_subtype
def test_construction_from_string_error_subtype(self, string):
# this is an invalid subtype
msg = ("Incorrectly formatted string passed to constructor. "
r"Valid formats include Interval or Interval\[dtype\] "
"where dtype is numeric, datetime, or timedelta")
with pytest.raises(TypeError, match=msg):
IntervalDtype.construct_from_string(string)
示例3: test_caching
def test_caching(self):
IntervalDtype.reset_cache()
dtype = IntervalDtype("int64")
assert len(IntervalDtype._cache) == 1
IntervalDtype("interval")
assert len(IntervalDtype._cache) == 2
IntervalDtype.reset_cache()
tm.round_trip_pickle(dtype)
assert len(IntervalDtype._cache) == 0
示例4: test_construction_from_string
def test_construction_from_string(self):
result = IntervalDtype('interval[int64]')
assert is_dtype_equal(self.dtype, result)
result = IntervalDtype.construct_from_string('interval[int64]')
assert is_dtype_equal(self.dtype, result)
with pytest.raises(TypeError):
IntervalDtype.construct_from_string('foo')
with pytest.raises(TypeError):
IntervalDtype.construct_from_string('interval[foo]')
with pytest.raises(TypeError):
IntervalDtype.construct_from_string('foo[int64]')
示例5: test_construction_from_string
def test_construction_from_string(self):
result = IntervalDtype('interval[int64]')
self.assertTrue(is_dtype_equal(self.dtype, result))
result = IntervalDtype.construct_from_string('interval[int64]')
self.assertTrue(is_dtype_equal(self.dtype, result))
with tm.assertRaises(TypeError):
IntervalDtype.construct_from_string('foo')
with tm.assertRaises(TypeError):
IntervalDtype.construct_from_string('interval[foo]')
with tm.assertRaises(TypeError):
IntervalDtype.construct_from_string('foo[int64]')
示例6: test_is_dtype
def test_is_dtype(self):
assert IntervalDtype.is_dtype(self.dtype)
assert IntervalDtype.is_dtype('interval')
assert IntervalDtype.is_dtype(IntervalDtype('float64'))
assert IntervalDtype.is_dtype(IntervalDtype('int64'))
assert IntervalDtype.is_dtype(IntervalDtype(np.int64))
assert not IntervalDtype.is_dtype('D')
assert not IntervalDtype.is_dtype('3D')
assert not IntervalDtype.is_dtype('U')
assert not IntervalDtype.is_dtype('S')
assert not IntervalDtype.is_dtype('foo')
assert not IntervalDtype.is_dtype(np.object_)
assert not IntervalDtype.is_dtype(np.int64)
assert not IntervalDtype.is_dtype(np.float64)
示例7: test_construction_from_string
def test_construction_from_string(self):
result = IntervalDtype('interval[int64]')
assert is_dtype_equal(self.dtype, result)
result = IntervalDtype.construct_from_string('interval[int64]')
assert is_dtype_equal(self.dtype, result)
示例8: test_construction_from_string_error_subtype
def test_construction_from_string_error_subtype(self, string):
# this is an invalid subtype
msg = 'could not construct IntervalDtype'
with tm.assert_raises_regex(TypeError, msg):
IntervalDtype.construct_from_string(string)
示例9: test_construction_from_string_errors
def test_construction_from_string_errors(self, string):
# these are invalid entirely
msg = 'a string needs to be passed, got type'
with tm.assert_raises_regex(TypeError, msg):
IntervalDtype.construct_from_string(string)
示例10: dtype
def dtype(self):
return IntervalDtype.construct_from_string(str(self.left.dtype))
示例11: test_construction_from_string_error_subtype
def test_construction_from_string_error_subtype(self, string):
# this is an invalid subtype
msg = 'could not construct IntervalDtype'
with pytest.raises(TypeError, match=msg):
IntervalDtype.construct_from_string(string)
示例12: test_construction_from_string_errors
def test_construction_from_string_errors(self, string):
# these are invalid entirely
msg = 'a string needs to be passed, got type'
with pytest.raises(TypeError, match=msg):
IntervalDtype.construct_from_string(string)
示例13: test_is_dtype
def test_is_dtype(self):
self.assertTrue(IntervalDtype.is_dtype(self.dtype))
self.assertTrue(IntervalDtype.is_dtype('interval'))
self.assertTrue(IntervalDtype.is_dtype(IntervalDtype('float64')))
self.assertTrue(IntervalDtype.is_dtype(IntervalDtype('int64')))
self.assertTrue(IntervalDtype.is_dtype(IntervalDtype(np.int64)))
self.assertFalse(IntervalDtype.is_dtype('D'))
self.assertFalse(IntervalDtype.is_dtype('3D'))
self.assertFalse(IntervalDtype.is_dtype('U'))
self.assertFalse(IntervalDtype.is_dtype('S'))
self.assertFalse(IntervalDtype.is_dtype('foo'))
self.assertFalse(IntervalDtype.is_dtype(np.object_))
self.assertFalse(IntervalDtype.is_dtype(np.int64))
self.assertFalse(IntervalDtype.is_dtype(np.float64))
示例14: dtype
def dtype(self):
"""Return the dtype object of the underlying data"""
return IntervalDtype.construct_from_string(str(self.left.dtype))