Skip to content

Commit 849a112

Browse files
committed
fix some dtype checking
1 parent cfa0ce4 commit 849a112

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

pandas/parser.pyx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ from pandas.core.common import (is_categorical_dtype, CategoricalDtype,
3838
is_integer_dtype, is_float_dtype,
3939
is_bool_dtype, is_object_dtype,
4040
is_string_dtype, is_datetime64_dtype)
41+
from pandas.types.api import pandas_dtype
4142
from pandas.core.categorical import Categorical
4243
from pandas.types.concat import union_categoricals
4344

@@ -492,22 +493,13 @@ cdef class TextReader:
492493
self.encoding = encoding
493494

494495
if isinstance(dtype, dict):
495-
conv = {}
496-
for k in dtype:
497-
v = dtype[k]
498-
if is_categorical_dtype(v):
499-
v = CategoricalDtype()
500-
elif isinstance(v, basestring):
501-
v = np.dtype(v)
502-
conv[k] = v
503-
dtype = conv
496+
dtype = {k: pandas_dtype(dtype[k])
497+
for k in dtype}
504498
elif dtype is not None:
505-
if is_categorical_dtype(dtype):
506-
dtype = CategoricalDtype()
507-
else:
508-
dtype = np.dtype(dtype)
499+
dtype = pandas_dtype(dtype)
509500

510501
self.dtype = dtype
502+
print dtype
511503

512504
# XXX
513505
self.noconvert = set()
@@ -1101,7 +1093,8 @@ cdef class TextReader:
11011093
col_dtype = self.dtype[i]
11021094
else:
11031095
if self.dtype.names:
1104-
col_dtype = self.dtype.descr[i][1]
1096+
# structured array
1097+
col_dtype = np.dtype(self.dtype.descr[i][1])
11051098
else:
11061099
col_dtype = self.dtype
11071100

@@ -1202,7 +1195,6 @@ cdef class TextReader:
12021195
# unicode variable width
12031196
return self._string_convert(i, start, end, na_filter,
12041197
na_hashset)
1205-
# is this comparison good enough?
12061198
elif is_categorical_dtype(dtype):
12071199
codes, cats, na_count = _categorical_convert(self.parser, i, start,
12081200
end, na_filter, na_hashset,

0 commit comments

Comments
 (0)