Skip to content

Commit 856753c

Browse files
committed
Make C engine the same as python parser engine
1 parent 0602556 commit 856753c

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

pandas/_libs/parsers.pyx

+24-11
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ from pandas.core.arrays import Categorical
5656
from pandas.core.dtypes.concat import union_categoricals
5757
import pandas.io.common as icom
5858

59-
from pandas.errors import (ParserError, DtypeWarning,
60-
EmptyDataError, ParserWarning)
59+
from pandas.errors import (
60+
ParserError, DtypeWarning,
61+
EmptyDataError, ParserWarning, AbstractMethodError,
62+
)
6163

6264
# Import CParserError as alias of ParserError for backwards compatibility.
6365
# Ultimately, we want to remove this import. See gh-12665 and gh-14479.
@@ -1232,10 +1234,16 @@ cdef class TextReader:
12321234
if result is not None and dtype != 'int64':
12331235
if is_extension_array_dtype(dtype):
12341236
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)
12391247
else:
12401248
result = result.astype(dtype)
12411249

@@ -1248,14 +1256,19 @@ cdef class TextReader:
12481256
if result is not None and dtype != 'float64':
12491257
if is_extension_array_dtype(dtype):
12501258
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)
12551269
else:
12561270
result = result.astype(dtype)
12571271
return result, na_count
1258-
12591272
elif is_bool_dtype(dtype):
12601273
result, na_count = _try_bool_flex(self.parser, i, start, end,
12611274
na_filter, na_hashset,

pandas/core/series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4354,7 +4354,8 @@ def _try_cast(arr, take_fast_path):
43544354
subarr = np.array(data, copy=False)
43554355

43564356
# possibility of nan -> garbage
4357-
if is_float_dtype(data.dtype) and is_integer_dtype(dtype):
4357+
if is_float_dtype(data.dtype) and is_integer_dtype(dtype) \
4358+
and not is_extension_array_dtype(dtype):
43584359
if not isna(data).any():
43594360
subarr = _try_cast(data, True)
43604361
elif copy:

pandas/tests/extension/base/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ class TestMyDtype(BaseDtypeTests):
5252
from .missing import BaseMissingTests # noqa
5353
from .reshaping import BaseReshapingTests # noqa
5454
from .setitem import BaseSetitemTests # noqa
55+
from .io import ExtensionParsingTests # noqa

0 commit comments

Comments
 (0)