Skip to content

Commit 124cb9f

Browse files
committed
PERF: Improve conversion in read_csv when string option is set
1 parent 8cbac01 commit 124cb9f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pandas/io/parsers/arrow_parser_wrapper.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,15 @@ def read(self) -> DataFrame:
267267
dtype_mapping[pa.null()] = pd.Int64Dtype()
268268
frame = table.to_pandas(types_mapper=dtype_mapping.get)
269269
elif using_pyarrow_string_dtype():
270-
frame = table.to_pandas(types_mapper=arrow_string_types_mapper())
270+
271+
def types_mapper(dtype):
272+
dtype_dict = self.kwds["dtype"]
273+
if dtype_dict is not None and dtype_dict.get(dtype, None) is not None:
274+
return dtype_dict.get(dtype)
275+
return arrow_string_types_mapper()(dtype)
276+
277+
frame = table.to_pandas(types_mapper=types_mapper)
278+
271279
else:
272280
if isinstance(self.kwds.get("dtype"), dict):
273281
frame = table.to_pandas(types_mapper=self.kwds["dtype"].get)

0 commit comments

Comments
 (0)