本文整理匯總了Python中pandas.core.dtypes.common.pandas_dtype方法的典型用法代碼示例。如果您正苦於以下問題:Python common.pandas_dtype方法的具體用法?Python common.pandas_dtype怎麽用?Python common.pandas_dtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.dtypes.common
的用法示例。
在下文中一共展示了common.pandas_dtype方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_dtype_equal_strict
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_dtype_equal_strict():
# we are strict on kind equality
for dtype in [np.int8, np.int16, np.int32]:
assert not com.is_dtype_equal(np.int64, dtype)
for dtype in [np.float32]:
assert not com.is_dtype_equal(np.float64, dtype)
# strict w.r.t. PeriodDtype
assert not com.is_dtype_equal(PeriodDtype('D'), PeriodDtype('2D'))
# strict w.r.t. datetime64
assert not com.is_dtype_equal(
com.pandas_dtype('datetime64[ns, US/Eastern]'),
com.pandas_dtype('datetime64[ns, CET]'))
# see gh-15941: no exception should be raised
assert not com.is_dtype_equal(None, None)
示例2: test_invalid_dtype_error
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_invalid_dtype_error(self, box):
with pytest.raises(TypeError, match='not understood'):
com.pandas_dtype(box)
示例3: test_pandas_dtype_valid
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_pandas_dtype_valid(self, dtype):
assert com.pandas_dtype(dtype) == dtype
示例4: test_numpy_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_numpy_dtype(self, dtype):
assert com.pandas_dtype(dtype) == np.dtype(dtype)
示例5: test_numpy_string_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_numpy_string_dtype(self):
# do not parse freq-like string as period dtype
assert com.pandas_dtype('U') == np.dtype('U')
assert com.pandas_dtype('S') == np.dtype('S')
示例6: test_datetimetz_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_datetimetz_dtype(self, dtype):
assert (com.pandas_dtype(dtype) ==
DatetimeTZDtype.construct_from_string(dtype))
assert com.pandas_dtype(dtype) == dtype
示例7: test_period_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_period_dtype(self, dtype):
assert com.pandas_dtype(dtype) is PeriodDtype(dtype)
assert com.pandas_dtype(dtype) == PeriodDtype(dtype)
assert com.pandas_dtype(dtype) == dtype
示例8: test_invalid_dtype_error
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_invalid_dtype_error(self, box):
with tm.assert_raises_regex(TypeError, 'not understood'):
com.pandas_dtype(box)
示例9: test_datetimetz_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_datetimetz_dtype(self, dtype):
assert com.pandas_dtype(dtype) is DatetimeTZDtype(dtype)
assert com.pandas_dtype(dtype) == DatetimeTZDtype(dtype)
assert com.pandas_dtype(dtype) == dtype
示例10: test_invalid_dtype_error
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_invalid_dtype_error(self):
msg = 'not understood'
invalid_list = [pd.Timestamp, 'pd.Timestamp', list]
for dtype in invalid_list:
with tm.assert_raises_regex(TypeError, msg):
com.pandas_dtype(dtype)
valid_list = [object, 'float64', np.object_, np.dtype('object'), 'O',
np.float64, float, np.dtype('float64')]
for dtype in valid_list:
com.pandas_dtype(dtype)
示例11: test_numpy_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_numpy_dtype(self):
for dtype in ['M8[ns]', 'm8[ns]', 'object', 'float64', 'int64']:
assert com.pandas_dtype(dtype) == np.dtype(dtype)
示例12: test_datetimetz_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_datetimetz_dtype(self):
for dtype in ['datetime64[ns, US/Eastern]',
'datetime64[ns, Asia/Tokyo]',
'datetime64[ns, UTC]']:
assert com.pandas_dtype(dtype) is DatetimeTZDtype(dtype)
assert com.pandas_dtype(dtype) == DatetimeTZDtype(dtype)
assert com.pandas_dtype(dtype) == dtype
示例13: test_categorical_dtype
# 需要導入模塊: from pandas.core.dtypes import common [as 別名]
# 或者: from pandas.core.dtypes.common import pandas_dtype [as 別名]
def test_categorical_dtype(self):
assert com.pandas_dtype('category') == CategoricalDtype()