pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.71k stars 17.92k forks source link

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

Open jbrockmendel opened 3 years ago

jbrockmendel commented 3 years ago
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

jbrockmendel commented 3 years ago

Hmm actually CDay is considered anchored, but that doesn't appear to be all that meaningful.