Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,9 +1429,22 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
and obj.freq is not None
and all(idx.freq == obj.freq for idx in to_concat_nonempty)
):
pairs = pairwise(to_concat_nonempty)
if all(pair[0][-1] + obj.freq == pair[1][0] for pair in pairs):
result._freq = obj.freq
freq = obj.freq
tz = getattr(self.dtype, "tz", None)
if isinstance(freq, Tick) or (tz is None and isinstance(freq, Day)):
# freq is a fixed delta in the stored i8 representation, so we
# can check boundary continuity without boxing endpoints to
# Timestamps and doing per-pair offset arithmetic.
step = Timedelta(freq).as_unit(self.unit)._value
i8s = [idx._data._ndarray.view("i8") for idx in to_concat_nonempty]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know these all have the same unit?

evenly_spaced = all(a[-1] + step == b[0] for a, b in pairwise(i8s))
else:
evenly_spaced = all(
pair[0][-1] + freq == pair[1][0]
for pair in pairwise(to_concat_nonempty)
)
if evenly_spaced:
result._freq = freq

return result

Expand Down
Loading