Skip to content

Commit 4f080b8

Browse files
authored
PERF: Improve conversion in read_csv when string option is set (#56046)
1 parent eb7a8c8 commit 4f080b8

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
@@ -295,7 +295,15 @@ def read(self) -> DataFrame:
295295
dtype_mapping[pa.null()] = pd.Int64Dtype()
296296
frame = table.to_pandas(types_mapper=dtype_mapping.get)
297297
elif using_pyarrow_string_dtype():
298-
frame = table.to_pandas(types_mapper=arrow_string_types_mapper())
298+
299+
def types_mapper(dtype):
300+
dtype_dict = self.kwds["dtype"]
301+
if dtype_dict is not None and dtype_dict.get(dtype, None) is not None:
302+
return dtype_dict.get(dtype)
303+
return arrow_string_types_mapper()(dtype)
304+
305+
frame = table.to_pandas(types_mapper=types_mapper)
306+
299307
else:
300308
if isinstance(self.kwds.get("dtype"), dict):
301309
frame = table.to_pandas(types_mapper=self.kwds["dtype"].get)

0 commit comments

Comments
 (0)