Skip to content

Commit dc49903

Browse files
phoflmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#52057: PERF: Fix performance regression in read_csv when converting datetimes
1 parent f74e0d2 commit dc49903

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pandas/io/parsers/base_parser.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
)
6767
from pandas.core.dtypes.missing import isna
6868

69-
from pandas import StringDtype
69+
from pandas import (
70+
DatetimeIndex,
71+
StringDtype,
72+
)
7073
from pandas.core import algorithms
7174
from pandas.core.arrays import (
7275
ArrowExtensionArray,
@@ -1115,14 +1118,19 @@ def converter(*date_cols, col: Hashable):
11151118
date_format.get(col) if isinstance(date_format, dict) else date_format
11161119
)
11171120

1118-
return tools.to_datetime(
1121+
result = tools.to_datetime(
11191122
ensure_object(strs),
11201123
format=date_fmt,
11211124
utc=False,
11221125
dayfirst=dayfirst,
11231126
errors="ignore",
11241127
cache=cache_dates,
1125-
)._values
1128+
)
1129+
if isinstance(result, DatetimeIndex):
1130+
arr = result.to_numpy()
1131+
arr.flags.writeable = True
1132+
return arr
1133+
return result._values
11261134
else:
11271135
try:
11281136
result = tools.to_datetime(

0 commit comments

Comments
 (0)