Skip to content

Commit

Permalink
Backport PR #52057 on branch 2.0.x (PERF: Fix performance regression …
Browse files Browse the repository at this point in the history
…in read_csv when converting datetimes) (#52278)

Backport PR #52057: PERF: Fix performance regression in read_csv when converting datetimes

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and phofl committed Mar 29, 2023
1 parent 75d7af3 commit 5508e73
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
)
from pandas.core.dtypes.missing import isna

from pandas import StringDtype
from pandas import (
DatetimeIndex,
StringDtype,
)
from pandas.core import algorithms
from pandas.core.arrays import (
ArrowExtensionArray,
Expand Down Expand Up @@ -1115,14 +1118,19 @@ def converter(*date_cols, col: Hashable):
date_format.get(col) if isinstance(date_format, dict) else date_format
)

return tools.to_datetime(
result = tools.to_datetime(
ensure_object(strs),
format=date_fmt,
utc=False,
dayfirst=dayfirst,
errors="ignore",
cache=cache_dates,
)._values
)
if isinstance(result, DatetimeIndex):
arr = result.to_numpy()
arr.flags.writeable = True
return arr
return result._values
else:
try:
result = tools.to_datetime(
Expand Down

0 comments on commit 5508e73

Please sign in to comment.