@@ -524,3 +524,42 @@ def test_is_complex_dtype():
524524
525525 assert com .is_complex_dtype (np .complex )
526526 assert com .is_complex_dtype (np .array ([1 + 1j , 5 ]))
527+
528+
529+ @pytest .mark .parametrize ('input_param,result' , [
530+ (int , np .dtype (int )),
531+ ('int32' , np .dtype ('int32' )),
532+ (float , np .dtype (float )),
533+ ('float64' , np .dtype ('float64' )),
534+ (np .dtype ('float64' ), np .dtype ('float64' )),
535+ pytest .mark .xfail ((str , np .dtype ('<U' )), ),
536+ (pd .Series ([1 , 2 ], dtype = np .dtype ('int16' )), np .dtype ('int16' )),
537+ (pd .Series (['a' , 'b' ]), np .dtype (object )),
538+ (pd .Index ([1 , 2 ]), np .dtype ('int64' )),
539+ (pd .Index (['a' , 'b' ]), np .dtype (object )),
540+ ('category' , 'category' ),
541+ (pd .Categorical (['a' , 'b' ]).dtype , CategoricalDtype ()),
542+ pytest .mark .xfail ((pd .Categorical (['a' , 'b' ]), CategoricalDtype ()),),
543+ (pd .CategoricalIndex (['a' , 'b' ]).dtype , CategoricalDtype ()),
544+ pytest .mark .xfail ((pd .CategoricalIndex (['a' , 'b' ]), CategoricalDtype ()),),
545+ (pd .DatetimeIndex ([1 , 2 ]), np .dtype ('<M8[ns]' )),
546+ (pd .DatetimeIndex ([1 , 2 ]).dtype , np .dtype ('<M8[ns]' )),
547+ ('<M8[ns]' , np .dtype ('<M8[ns]' )),
548+ ('datetime64[ns, Europe/London]' , DatetimeTZDtype ('ns' , 'Europe/London' )),
549+ (pd .SparseSeries ([1 , 2 ], dtype = 'int32' ), np .dtype ('int32' )),
550+ (pd .SparseSeries ([1 , 2 ], dtype = 'int32' ).dtype , np .dtype ('int32' )),
551+ (PeriodDtype (freq = 'D' ), PeriodDtype (freq = 'D' )),
552+ ('period[D]' , PeriodDtype (freq = 'D' )),
553+ (IntervalDtype (), IntervalDtype ()),
554+ ])
555+ def test__get_dtype (input_param , result ):
556+ assert com ._get_dtype (input_param ) == result
557+
558+
559+ @pytest .mark .parametrize ('input_param' , [None ,
560+ 1 , 1.2 ,
561+ 'random string' ,
562+ pd .DataFrame ([1 , 2 ])])
563+ def test__get_dtype_fails (input_param ):
564+ # python objects
565+ pytest .raises (TypeError , com ._get_dtype , input_param )
0 commit comments