@@ -56,8 +56,10 @@ from pandas.core.arrays import Categorical
56
56
from pandas.core.dtypes.concat import union_categoricals
57
57
import pandas.io.common as icom
58
58
59
- from pandas.errors import (ParserError, DtypeWarning,
60
- EmptyDataError, ParserWarning)
59
+ from pandas.errors import (
60
+ ParserError, DtypeWarning,
61
+ EmptyDataError, ParserWarning, AbstractMethodError,
62
+ )
61
63
62
64
# Import CParserError as alias of ParserError for backwards compatibility.
63
65
# Ultimately, we want to remove this import. See gh-12665 and gh-14479.
@@ -1232,10 +1234,16 @@ cdef class TextReader:
1232
1234
if result is not None and dtype != ' int64' :
1233
1235
if is_extension_array_dtype(dtype):
1234
1236
try :
1235
- result = dtype.construct_array_type()._from_sequence(
1236
- result, dtype = dtype)
1237
- except Exception as e:
1238
- raise
1237
+ array_type = dtype.construct_array_type()
1238
+ except AttributeError :
1239
+ dtype = pandas_dtype(dtype)
1240
+ array_type = dtype.construct_array_type()
1241
+ try :
1242
+ # use _from_sequence_of_strings if the class defines it
1243
+ return array_type._from_sequence_of_strings(result,
1244
+ dtype = dtype) # noqa
1245
+ except AbstractMethodError:
1246
+ return array_type._from_sequence(result, dtype = dtype)
1239
1247
else :
1240
1248
result = result.astype(dtype)
1241
1249
@@ -1248,14 +1256,19 @@ cdef class TextReader:
1248
1256
if result is not None and dtype != ' float64' :
1249
1257
if is_extension_array_dtype(dtype):
1250
1258
try :
1251
- result = dtype.construct_array_type()._from_sequence(
1252
- result)
1253
- except Exception as e:
1254
- raise
1259
+ array_type = dtype.construct_array_type()
1260
+ except AttributeError :
1261
+ dtype = pandas_dtype(dtype)
1262
+ array_type = dtype.construct_array_type()
1263
+ try :
1264
+ # use _from_sequence_of_strings if the class defines it
1265
+ return array_type._from_sequence_of_strings(result,
1266
+ dtype = dtype) # noqa
1267
+ except AbstractMethodError:
1268
+ return array_type._from_sequence(result, dtype = dtype)
1255
1269
else :
1256
1270
result = result.astype(dtype)
1257
1271
return result, na_count
1258
-
1259
1272
elif is_bool_dtype(dtype):
1260
1273
result, na_count = _try_bool_flex(self .parser, i, start, end,
1261
1274
na_filter, na_hashset,
0 commit comments