Skip to content

Commit cfcc4c2

Browse files
author
analyticalmonk
committed
modified pandas_dtype() to raise error when provided invalid dtype as per pandas-dev#15520
This change ensures that no error is raised when type 'object' is passed.
1 parent 47e1680 commit cfcc4c2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pandas/core/dtypes/common.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,23 @@ def pandas_dtype(dtype):
731731
except TypeError:
732732
pass
733733

734+
elif dtype == 'object':
735+
return np.dtype(dtype)
736+
734737
try:
735738
return CategoricalDtype.construct_from_string(dtype)
736739
except TypeError:
737740
pass
738741
elif isinstance(dtype, ExtensionDtype):
739742
return dtype
740-
elif np.dtype(dtype).kind == 'O':
741-
raise TypeError("data type {0} not understood".format(dtype))
743+
else:
744+
try:
745+
np.dtype(dtype)
746+
except (TypeError, ValueError):
747+
raise
748+
if dtype == object:
749+
return np.dtype(dtype)
750+
elif np.dtype(dtype).kind == 'O':
751+
raise TypeError('dtype {0} not understood'.format(dtype))
742752

743753
return np.dtype(dtype)

0 commit comments

Comments
 (0)