Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: DatetimeIndex intersection with non-anchored freq #62341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
arthurlw wants to merge 1 commit into pandas-dev:main
base: main
Choose a base branch
Loading
from arthurlw:custom_datetimeindex_intersection
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
View file Open in desktop
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

@jbrockmendel jbrockmendel Sep 15, 2025

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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /