Skip to content

Commit beec0e8

Browse files
authored
PERF: Fix performance regression in read_csv when converting datetimes (#52057)
1 parent 2736ec8 commit beec0e8

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
@@ -60,7 +60,10 @@
6060
)
6161
from pandas.core.dtypes.missing import isna
6262

63-
from pandas import StringDtype
63+
from pandas import (
64+
DatetimeIndex,
65+
StringDtype,
66+
)
6467
from pandas.core import algorithms
6568
from pandas.core.arrays import (
6669
ArrowExtensionArray,
@@ -1116,14 +1119,19 @@ def converter(*date_cols, col: Hashable):
11161119
date_format.get(col) if isinstance(date_format, dict) else date_format
11171120
)
11181121

1119-
return tools.to_datetime(
1122+
result = tools.to_datetime(
11201123
ensure_object(strs),
11211124
format=date_fmt,
11221125
utc=False,
11231126
dayfirst=dayfirst,
11241127
errors="ignore",
11251128
cache=cache_dates,
1126-
)._values
1129+
)
1130+
if isinstance(result, DatetimeIndex):
1131+
arr = result.to_numpy()
1132+
arr.flags.writeable = True
1133+
return arr
1134+
return result._values
11271135
else:
11281136
try:
11291137
result = tools.to_datetime(

0 commit comments

Comments
 (0)