Skip to content

Commit 964234b

Browse files
author
tp
committed
Added test for _get_dtype_type.
1 parent a9421af commit 964234b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/dtypes/test_common.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,37 @@ def test__get_dtype(input_param, result):
563563
def test__get_dtype_fails(input_param):
564564
# python objects
565565
pytest.raises(TypeError, com._get_dtype, input_param)
566+
567+
568+
@pytest.mark.parametrize('input_param,result', [
569+
(int, np.dtype(int).type),
570+
('int32', np.int32),
571+
(float, np.dtype(float).type),
572+
('float64', np.float64),
573+
(np.dtype('float64'), np.float64),
574+
(str, np.dtype(str).type),
575+
(pd.Series([1, 2], dtype=np.dtype('int16')), np.int16),
576+
(pd.Series(['a', 'b']), np.object_),
577+
(pd.Index([1, 2], dtype='int64'), np.int64),
578+
(pd.Index(['a', 'b']), np.object_),
579+
('category', com.CategoricalDtypeType),
580+
(pd.Categorical(['a', 'b']).dtype, com.CategoricalDtypeType),
581+
(pd.Categorical(['a', 'b']), com.CategoricalDtypeType),
582+
(pd.CategoricalIndex(['a', 'b']).dtype, com.CategoricalDtypeType),
583+
(pd.CategoricalIndex(['a', 'b']), com.CategoricalDtypeType),
584+
(pd.DatetimeIndex([1, 2]), np.datetime64),
585+
(pd.DatetimeIndex([1, 2]).dtype, np.datetime64),
586+
('<M8[ns]', np.datetime64),
587+
('datetime64[ns, Europe/London]', com.DatetimeTZDtypeType),
588+
(pd.SparseSeries([1, 2], dtype='int32'), np.int32),
589+
(pd.SparseSeries([1, 2], dtype='int32').dtype, np.int32),
590+
(PeriodDtype(freq='D'), com.PeriodDtypeType),
591+
('period[D]', com.PeriodDtypeType),
592+
(IntervalDtype(), com.IntervalDtypeType),
593+
(None, type(None)),
594+
(1, type(None)),
595+
(1.2, type(None)),
596+
(pd.DataFrame([1, 2]), type(None)),
597+
])
598+
def test__get_dtype_type(input_param, result):
599+
assert com._get_dtype_type(input_param) == result

0 commit comments

Comments
 (0)