@@ -10,7 +10,6 @@ import sys
10
10
import time
11
11
import warnings
12
12
13
- from pandas.errors import ParserError
14
13
from pandas.util._exceptions import find_stack_level
15
14
16
15
from pandas import StringDtype
@@ -106,15 +105,10 @@ from pandas.errors import (
106
105
ParserWarning,
107
106
)
108
107
109
- from pandas.core.dtypes.common import (
110
- is_bool_dtype,
111
- is_datetime64_dtype,
112
- is_extension_array_dtype,
113
- is_float_dtype,
114
- is_integer_dtype,
115
- is_object_dtype,
108
+ from pandas.core.dtypes.dtypes import (
109
+ CategoricalDtype,
110
+ ExtensionDtype,
116
111
)
117
- from pandas.core.dtypes.dtypes import CategoricalDtype
118
112
from pandas.core.dtypes.inference import is_dict_like
119
113
120
114
cdef:
@@ -1077,7 +1071,7 @@ cdef class TextReader:
1077
1071
1078
1072
# don't try to upcast EAs
1079
1073
if (
1080
- na_count > 0 and not is_extension_array_dtype (col_dtype)
1074
+ na_count > 0 and not isinstance (col_dtype, ExtensionDtype )
1081
1075
or self .dtype_backend != " numpy"
1082
1076
):
1083
1077
use_dtype_backend = self .dtype_backend != " numpy" and col_dtype is None
@@ -1142,14 +1136,14 @@ cdef class TextReader:
1142
1136
# (see _try_bool_flex()). Usually this would be taken care of using
1143
1137
# _maybe_upcast(), but if col_dtype is a floating type we should just
1144
1138
# take care of that cast here.
1145
- if col_res.dtype == np.bool_ and is_float_dtype( col_dtype) :
1139
+ if col_res.dtype == np.bool_ and col_dtype.kind == " f " :
1146
1140
mask = col_res.view(np.uint8) == na_values[np.uint8]
1147
1141
col_res = col_res.astype(col_dtype)
1148
1142
np.putmask(col_res, mask, np.nan)
1149
1143
return col_res, na_count
1150
1144
1151
1145
# NaNs are already cast to True here, so can not use astype
1152
- if col_res.dtype == np.bool_ and is_integer_dtype( col_dtype) :
1146
+ if col_res.dtype == np.bool_ and col_dtype.kind in " iu " :
1153
1147
if na_count > 0 :
1154
1148
raise ValueError (
1155
1149
f" cannot safely convert passed user dtype of "
@@ -1193,14 +1187,14 @@ cdef class TextReader:
1193
1187
cats, codes, dtype, true_values = true_values)
1194
1188
return cat, na_count
1195
1189
1196
- elif is_extension_array_dtype (dtype):
1190
+ elif isinstance (dtype, ExtensionDtype ):
1197
1191
result, na_count = self ._string_convert(i, start, end, na_filter,
1198
1192
na_hashset)
1199
1193
1200
1194
array_type = dtype.construct_array_type()
1201
1195
try :
1202
1196
# use _from_sequence_of_strings if the class defines it
1203
- if is_bool_dtype( dtype) :
1197
+ if dtype.kind == " b " :
1204
1198
true_values = [x.decode() for x in self .true_values]
1205
1199
false_values = [x.decode() for x in self .false_values]
1206
1200
result = array_type._from_sequence_of_strings(
@@ -1216,7 +1210,7 @@ cdef class TextReader:
1216
1210
1217
1211
return result, na_count
1218
1212
1219
- elif is_integer_dtype( dtype) :
1213
+ elif dtype.kind in " iu " :
1220
1214
try :
1221
1215
result, na_count = _try_int64(self .parser, i, start,
1222
1216
end, na_filter, na_hashset)
@@ -1233,14 +1227,14 @@ cdef class TextReader:
1233
1227
1234
1228
return result, na_count
1235
1229
1236
- elif is_float_dtype( dtype) :
1230
+ elif dtype.kind == " f " :
1237
1231
result, na_count = _try_double(self .parser, i, start, end,
1238
1232
na_filter, na_hashset, na_flist)
1239
1233
1240
1234
if result is not None and dtype != " float64" :
1241
1235
result = result.astype(dtype)
1242
1236
return result, na_count
1243
- elif is_bool_dtype( dtype) :
1237
+ elif dtype.kind == " b " :
1244
1238
result, na_count = _try_bool_flex(self .parser, i, start, end,
1245
1239
na_filter, na_hashset,
1246
1240
self .true_set, self .false_set)
@@ -1267,10 +1261,10 @@ cdef class TextReader:
1267
1261
# unicode variable width
1268
1262
return self ._string_convert(i, start, end, na_filter,
1269
1263
na_hashset)
1270
- elif is_object_dtype( dtype) :
1264
+ elif dtype == object :
1271
1265
return self ._string_convert(i, start, end, na_filter,
1272
1266
na_hashset)
1273
- elif is_datetime64_dtype( dtype) :
1267
+ elif dtype.kind == " M " :
1274
1268
raise TypeError (f" the dtype {dtype} is not supported "
1275
1269
f" for parsing, pass this column "
1276
1270
f" using parse_dates instead" )
@@ -1438,7 +1432,7 @@ def _maybe_upcast(
1438
1432
-------
1439
1433
The casted array.
1440
1434
"""
1441
- if is_extension_array_dtype (arr.dtype):
1435
+ if isinstance (arr.dtype, ExtensionDtype ):
1442
1436
# TODO: the docstring says arr is an ndarray, in which case this cannot
1443
1437
# be reached. Is that incorrect?
1444
1438
return arr
0 commit comments