Skip to content

Commit 5994a33

Browse files
committed
ENH:Add EA types to read CSV
Closes GH23228
1 parent c911151 commit 5994a33

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

pandas/_libs/parsers.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,10 @@ cdef class TextReader:
12291229
na_count = 0
12301230

12311231
if result is not None and dtype != 'int64':
1232-
result = result.astype(dtype)
1232+
try:
1233+
result = result.astype(dtype)
1234+
except TypeError:
1235+
result = result.astype(dtype.numpy_dtype)
12331236

12341237
return result, na_count
12351238

@@ -1238,7 +1241,10 @@ cdef class TextReader:
12381241
na_filter, na_hashset, na_flist)
12391242

12401243
if result is not None and dtype != 'float64':
1241-
result = result.astype(dtype)
1244+
try:
1245+
result = result.astype(dtype)
1246+
except TypeError:
1247+
result = result.astype(dtype.numpy_dtype)
12421248
return result, na_count
12431249

12441250
elif is_bool_dtype(dtype):

pandas/core/dtypes/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,10 @@ def _get_dtype_type(arr_or_dtype):
18721872
try:
18731873
return arr_or_dtype.dtype.type
18741874
except AttributeError:
1875-
return type(None)
1875+
try:
1876+
return arr_or_dtype.numpy_dtype.type
1877+
except AttributeError:
1878+
return type(None)
18761879

18771880

18781881
def _get_dtype_from_object(dtype):

pandas/tests/io/parser/common.py

Whitespace-only changes.

0 commit comments

Comments
 (0)