Skip to content

Commit

Permalink
PERF: Improve conversion in read_csv when string option is set (#56046)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Nov 30, 2023
1 parent eb7a8c8 commit 4f080b8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pandas/io/parsers/arrow_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,15 @@ def read(self) -> DataFrame:
dtype_mapping[pa.null()] = pd.Int64Dtype()
frame = table.to_pandas(types_mapper=dtype_mapping.get)
elif using_pyarrow_string_dtype():
frame = table.to_pandas(types_mapper=arrow_string_types_mapper())

def types_mapper(dtype):
dtype_dict = self.kwds["dtype"]
if dtype_dict is not None and dtype_dict.get(dtype, None) is not None:
return dtype_dict.get(dtype)
return arrow_string_types_mapper()(dtype)

frame = table.to_pandas(types_mapper=types_mapper)

else:
if isinstance(self.kwds.get("dtype"), dict):
frame = table.to_pandas(types_mapper=self.kwds["dtype"].get)
Expand Down

0 comments on commit 4f080b8

Please sign in to comment.