Skip to content

Commit c1a9049

Browse files
committed
PERF: speed up tz-aware datetimearray ops by skipping useless validation
1 parent 62506ca commit c1a9049

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,7 @@ Performance Improvements
13271327
- Improved performance of iterating over a :class:`Series`. Using :meth:`DataFrame.itertuples` now creates iterators
13281328
without internally allocating lists of all elements (:issue:`20783`)
13291329
- Improved performance of :class:`Period` constructor, additionally benefitting ``PeriodArray`` and ``PeriodIndex`` creation (:issue:`24084` and :issue:`24118`)
1330+
- Improved performance of tz-aware :class:`DatetimeArray` binary operations (:issue:`24491`)
13301331

13311332
.. _whatsnew_0240.docs:
13321333

pandas/core/arrays/datetimes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ def _from_sequence(cls, data, dtype=None, copy=False,
335335
cls._validate_frequency(result, freq, ambiguous=ambiguous)
336336

337337
elif freq_infer:
338-
result.freq = to_offset(result.inferred_freq)
338+
# Set _freq directly to bypass duplicative _validate_frequency
339+
# check.
340+
result._freq = to_offset(result.inferred_freq)
339341

340342
return result
341343

pandas/core/arrays/timedeltas.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def _from_sequence(cls, data, dtype=_TD_DTYPE, copy=False,
200200
cls._validate_frequency(result, freq)
201201

202202
elif freq_infer:
203-
result.freq = to_offset(result.inferred_freq)
203+
# Set _freq directly to bypass duplicative _validate_frequency
204+
# check.
205+
result._freq = to_offset(result.inferred_freq)
204206

205207
return result
206208

0 commit comments

Comments
 (0)