Skip to content

API: allow step!=1 slice with IntervalIndex #31658

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

Merged
merged 30 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7a26837
Allow step!=1 in slicing Series with IntervalIndex
jbrockmendel Feb 2, 2020
b371805
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 3, 2020
b78c4c3
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 3, 2020
e3631d9
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 3, 2020
7949ffd
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 3, 2020
4c2e703
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 4, 2020
88a7ace
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 4, 2020
0da92c5
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 4, 2020
f833f7c
Whatsnew
jbrockmendel Feb 5, 2020
041edbc
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 6, 2020
a2eb9bb
doc suggestion
jbrockmendel Feb 6, 2020
6b97b09
test for interval step
jbrockmendel Feb 6, 2020
abdbd76
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 6, 2020
a678ec2
remove commented-out
jbrockmendel Feb 6, 2020
2c684cc
reword whatsnew
jbrockmendel Feb 6, 2020
e4cc38d
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 6, 2020
10165b4
disallow label-based with step!=1
jbrockmendel Feb 6, 2020
8308eb8
black fixup
jbrockmendel Feb 6, 2020
2bffbda
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 17, 2020
0bdb7b5
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 22, 2020
adf0775
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 25, 2020
2744a4b
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Feb 25, 2020
cf1a393
update error message
jbrockmendel Feb 25, 2020
74a40ff
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 2, 2020
9a04d41
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 3, 2020
f6360a6
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 3, 2020
d636108
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 5, 2020
9222513
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 5, 2020
2a698c0
typo fixup
jbrockmendel Mar 7, 2020
d18c7a1
Merge branch 'master' of https://github.com/pandas-dev/pandas into co…
jbrockmendel Mar 7, 2020
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 doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Strings

Interval
^^^^^^^^

- Bug in :class:`IntervalIndex` slicing that prevented slicing with ``step > 1`` (:issue:`31658`)
Copy link
Member

Choose a reason for hiding this comment

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

I would put this in the "other enhancements" section

-
-

Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,6 @@ def get_indexer_for(self, target: AnyArrayLike, **kwargs) -> np.ndarray:
return self.get_indexer_non_unique(target)[0]
return self.get_indexer(target, **kwargs)

def _convert_slice_indexer(self, key: slice, kind=None):
if not (key.step is None or key.step == 1):
raise ValueError("cannot support not-default step in a slice")
return super()._convert_slice_indexer(key, kind)

@Appender(Index.where.__doc__)
def where(self, cond, other=None):
if other is None:
Expand Down
12 changes: 10 additions & 2 deletions pandas/tests/indexing/interval/test_interval_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_loc_with_slices(self):
with pytest.raises(NotImplementedError, match=msg):
s[Interval(3, 4, closed="left") :]

# FIXME: dont leave commented-out
# TODO with non-existing intervals ?
# s.loc[Interval(-1, 0):Interval(2, 3)]

Expand All @@ -143,9 +144,16 @@ def test_loc_with_slices(self):
tm.assert_series_equal(expected, s[:2.5])
tm.assert_series_equal(expected, s[0.1:2.5])

def test_slice_step_ne1(self):
# slice of scalar with step != 1
with pytest.raises(ValueError):
s[0:4:2]
s = self.s
expected = s.iloc[0:4:2]

result = s[0:4:2]
tm.assert_series_equal(result, expected)

result2 = s[0:4][::2]
tm.assert_series_equal(result2, expected)

def test_loc_with_overlap(self):

Expand Down