Skip to content

Commit e935829

Browse files
committed
PERF: speed up tz-aware datetimearray ops by skipping useless validation
1 parent 02a97c0 commit e935829

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

doc/source/whatsnew/v0.24.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ Performance Improvements
12951295
- Improved performance of iterating over a :class:`Series`. Using :meth:`DataFrame.itertuples` now creates iterators
12961296
without internally allocating lists of all elements (:issue:`20783`)
12971297
- Improved performance of :class:`Period` constructor, additionally benefitting ``PeriodArray`` and ``PeriodIndex`` creation (:issue:`24084` and :issue:`24118`)
1298+
- Improved performance of tz-aware :class:`DatetimeArray` binary operations (:issue:`24491`)
12981299

12991300
.. _whatsnew_0240.docs:
13001301

pandas/core/arrays/datetimes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ def _from_sequence(cls, data, dtype=None, copy=False,
262262
cls._validate_frequency(result, freq, ambiguous=ambiguous)
263263

264264
elif freq_infer:
265-
result.freq = to_offset(result.inferred_freq)
265+
# Set _freq directly to bypass duplicative _validate_frequency
266+
# check.
267+
result._freq = to_offset(result.inferred_freq)
266268

267269
return result
268270

pandas/core/arrays/timedeltas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ def _from_sequence(cls, data, dtype=_TD_DTYPE, copy=False,
181181
cls._validate_frequency(result, freq)
182182

183183
elif freq_infer:
184-
result.freq = to_offset(result.inferred_freq)
184+
# Set _freq directly to bypass duplicative _validate_frequency
185+
# check.
186+
result._freq = to_offset(result.inferred_freq)
185187

186188
return result
187189

0 commit comments

Comments
 (0)