Skip to content

Commit fecba12

Browse files
BUG: Raise when invalid dtype passed to pandas_dtype
Changes made to pandas_dtype() in pandas/core/dtypes/common.py
1 parent 99fb660 commit fecba12

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/core/dtypes/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,7 @@ def pandas_dtype(dtype):
737737
pass
738738
elif isinstance(dtype, ExtensionDtype):
739739
return dtype
740+
elif np.dtype(dtype).kind == 'O':
741+
raise TypeError("data type {0} not understood".format(dtype))
740742

741743
return np.dtype(dtype)

pandas/core/generic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
is_datetime64tz_dtype,
2424
is_list_like,
2525
is_dict_like,
26-
is_re_compilable)
26+
is_re_compilable,
27+
pandas_dtype)
2728
from pandas.core.dtypes.cast import maybe_promote, maybe_upcast_putmask
2829
from pandas.core.dtypes.missing import isnull, notnull
2930
from pandas.core.dtypes.generic import ABCSeries, ABCPanel
@@ -165,12 +166,15 @@ def _validate_dtype(self, dtype):
165166

166167
if dtype is not None:
167168
dtype = _coerce_to_dtype(dtype)
169+
# This would raise an error if an invalid dtype was passed
170+
dtype = pandas_dtype(dtype)
168171

169172
# a compound dtype
170173
if dtype.kind == 'V':
171174
raise NotImplementedError("compound dtypes are not implemented"
172175
"in the {0} constructor"
173176
.format(self.__class__.__name__))
177+
174178
return dtype
175179

176180
def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):

0 commit comments

Comments
 (0)