Skip to content

BUG: DatetimeIndex.intersection with non-anchored freq #44025

@jbrockmendel

Description

@jbrockmendel
import pandas as pd

off = pd.offsets.CDay(1, False)

ts = pd.Timestamp("2021-10-13 09")
ts2 = ts + pd.Timedelta("1 hour")

dti = pd.date_range(start=ts, periods=10, freq=off)
dti2 = pd.date_range(start=ts2, periods=10, freq=off)

assert set(dti).intersection(set(dti2)) == set()  # yep!

res = dti.intersection(dti2)
assert len(res) == 0  # nope!

_can_fast_intersect is wrong for the non-anchored case, returning self.freq.n == 1 which is not sufficient in this case. It may be that we just need to return False for non-anchored.

Expected Behavior

The intersection should be empty

Metadata

Metadata

Assignees

Labels

BugFrequencyDateOffsetsIndexRelated to the Index class or subclassessetopsunion, intersection, difference, symmetric_difference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions