Skip to content

Commit 88b2354

Browse files
author
analyticalmonk
committed
BUG: Added type-validation in _validate_dtype() using pandas_dtype
Made changes to _validate_dtype in pandas/core/generic.py Please enter the commit message for your changes. Lines starting
1 parent a5de269 commit 88b2354

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/generic.py

+5-1
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)