Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def _fast_intersect(self, other, sort):

def _can_fast_intersect(self, other: Self) -> bool:
# Note: we only get here with len(self) > 0 and len(other) > 0
if self.freq is None:
if self.freq is None or self.freq == "C":
Copy link
Member

Choose a reason for hiding this comment

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

the issue isn't just handling "C", but identifying what conditions work in the general case

return False

elif other.freq != self.freq:
Expand Down
15 changes: 14 additions & 1 deletion pandas/tests/indexes/datetimes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import pytest

from pandas._libs.tslibs.timedeltas import Timedelta
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -709,7 +710,6 @@ def test_intersection_bug(self):
b = bdate_range("12/10/2011", "12/20/2011", freq="C")
result = a.intersection(b)
tm.assert_index_equal(result, b)
assert result.freq == b.freq

@pytest.mark.parametrize(
"tz", [None, "UTC", "Europe/Berlin", timezone(timedelta(hours=-1))]
Expand Down Expand Up @@ -757,3 +757,16 @@ def test_intersection_non_nano_rangelike():
freq="D",
)
tm.assert_index_equal(result, expected)


def test_cday_intersection_empty():
# GH#44025
off = pd.offsets.CDay(1, normalize=False)
ts = Timestamp("2021-10-13 09:00")
ts2 = ts + Timedelta("1 hour")

dti1 = date_range(start=ts, periods=10, freq=off)
dti2 = date_range(start=ts2, periods=10, freq=off)
result = dti1.intersection(dti2)
expected = DatetimeIndex([], dtype="datetime64[ns]")
tm.assert_index_equal(result, expected)
Loading