Skip to content

Commit 2c3d27a

Browse files
committed
Fix low_memory C engine parser
1 parent 9746e4b commit 2c3d27a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

pandas/_libs/parsers.pyx

+6-3
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,6 @@ cdef class TextReader:
986986
footer=footer,
987987
upcast_na=True)
988988
self._end_clock('Type conversion')
989-
990989
self._start_clock()
991990
if len(columns) > 0:
992991
rows_read = len(list(columns.values())[0])
@@ -1241,7 +1240,7 @@ cdef class TextReader:
12411240
try:
12421241
# use _from_sequence_of_strings if the class defines it
12431242
result = array_type._from_sequence_of_strings(result,
1244-
dtype=dtype) # noqa
1243+
dtype=dtype) # noqa
12451244
except AbstractMethodError:
12461245
result = array_type._from_sequence(result, dtype=dtype)
12471246
else:
@@ -2201,7 +2200,11 @@ def _concatenate_chunks(list chunks):
22012200
result[name] = union_categoricals(arrs,
22022201
sort_categories=sort_categories)
22032202
else:
2204-
result[name] = np.concatenate(arrs)
2203+
if is_extension_array_dtype(dtype):
2204+
result[name] = dtype \
2205+
.construct_array_type()._concat_same_type(arrs)
2206+
else:
2207+
result[name] = np.concatenate(arrs)
22052208

22062209
if warning_columns:
22072210
warning_names = ','.join(warning_columns)

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def sanitize_array(data, index, dtype=None, copy=False,
559559

560560
# possibility of nan -> garbage
561561
if is_float_dtype(data.dtype) and is_integer_dtype(dtype) \
562-
and not is_extension_array_dtype(dtype):
562+
and not is_extension_array_dtype(dtype):
563563
if not isna(data).any():
564564
subarr = _try_cast(data, True, dtype, copy,
565565
raise_cast_failure)

pandas/io/parsers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
16691669
try_num_bool)
16701670

16711671
# type specified in dtype param
1672-
if cast_type and not is_dtype_equal(cvals, cast_type):
1673-
# or is_extension_array_dtype(cast_type)):
1672+
if cast_type and (not is_dtype_equal(cvals, cast_type)
1673+
or is_extension_array_dtype(cast_type)):
16741674
try:
16751675
if (is_bool_dtype(cast_type) and
16761676
not is_categorical_dtype(cast_type)

pandas/tests/extension/base/io.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ def data(dtype):
2626

2727

2828
class ExtensionParsingTests(BaseExtensionTests):
29-
def test_EA_types(self):
29+
30+
@pytest.mark.parametrize('engine', ['c', 'python'])
31+
def test_EA_types(self, engine):
3032
df = pd.DataFrame({'Int': pd.Series([1, 2, 3], dtype='Int64'),
3133
'A': [1, 2, 1]})
3234
data = df.to_csv(index=False)
33-
result = pd.read_csv(StringIO(data), dtype={'Int': Int64Dtype})
35+
result = pd.read_csv(StringIO(data), dtype={'Int': Int64Dtype},
36+
engine=engine)
3437
assert result is not None
3538

3639
df = pd.DataFrame({'Int': pd.Series([1, 2, 3], dtype='Int8'),
3740
'A': [1, 2, 1]})
3841
data = df.to_csv(index=False)
39-
result = pd.read_csv(StringIO(data), dtype={'Int': 'Int8'})
42+
result = pd.read_csv(StringIO(data), dtype={'Int': 'Int8'},
43+
engine=engine)
4044
assert result is not None

0 commit comments

Comments
 (0)