Skip to content

Commit 03d632c

Browse files
qwhelanJustinZhengBC
authored andcommitted
PERF: define is_all_dates to shortcut inadvertent copy when slicing an IntervalIndex (pandas-dev#23591)
1 parent 6244f35 commit 03d632c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pandas/core/indexes/interval.py

+8
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,14 @@ def func(self, other):
10611061
name=result_name)
10621062
return func
10631063

1064+
@property
1065+
def is_all_dates(self):
1066+
"""
1067+
This is False even when left/right contain datetime-like objects,
1068+
as the check is done on the Interval itself
1069+
"""
1070+
return False
1071+
10641072
union = _setop('union')
10651073
intersection = _setop('intersection')
10661074
difference = _setop('difference')

pandas/tests/indexes/interval/test_interval.py

+7
Original file line numberDiff line numberDiff line change
@@ -1150,3 +1150,10 @@ def test_set_closed_errors(self, bad_closed):
11501150
msg = "invalid option for 'closed': {closed}".format(closed=bad_closed)
11511151
with tm.assert_raises_regex(ValueError, msg):
11521152
index.set_closed(bad_closed)
1153+
1154+
def test_is_all_dates(self):
1155+
# GH 23576
1156+
year_2017 = pd.Interval(pd.Timestamp('2017-01-01 00:00:00'),
1157+
pd.Timestamp('2018-01-01 00:00:00'))
1158+
year_2017_index = pd.IntervalIndex([year_2017])
1159+
assert not year_2017_index.is_all_dates

0 commit comments

Comments
 (0)