Skip to content

Commit

Permalink
Drop kind parameter from Index.get_slice_bound (#12856)
Browse files Browse the repository at this point in the history
This PR drops `kind` parameter from `Index.get_slice_bound` to match pandas-2.0 API.
  • Loading branch information
galipremsagar authored Mar 8, 2023
1 parent 620e35f commit 7ec76b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 58 deletions.
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ def rename(self, name, inplace=False):
out.name = name
return out

def get_slice_bound(self, label, side, kind=None):
def get_slice_bound(self, label, side):
"""
Calculate slice bound that corresponds to given label.
Returns leftmost (one-past-the-rightmost if ``side=='right'``) position
Expand All @@ -1422,7 +1422,6 @@ def get_slice_bound(self, label, side, kind=None):
----------
label : object
side : {'left', 'right'}
kind : {'ix', 'loc', 'getitem'}
Returns
-------
Expand Down
12 changes: 2 additions & 10 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def is_monotonic_decreasing(self) -> bool:
ascending=[False], null_position=None
)

def get_slice_bound(self, label: ScalarLike, side: str, kind: str) -> int:
def get_slice_bound(self, label: ScalarLike, side: str) -> int:
"""
Calculate slice bound that corresponds to given label.
Returns leftmost (one-past-the-rightmost if ``side=='right'``) position
Expand All @@ -893,22 +893,14 @@ def get_slice_bound(self, label: ScalarLike, side: str, kind: str) -> int:
----------
label : Scalar
side : {'left', 'right'}
kind : {'ix', 'loc', 'getitem'}
"""
if kind not in {"ix", "loc", "getitem", None}:
raise ValueError(
f"Invalid value for ``kind`` parameter,"
f" must be either one of the following: "
f"{'ix', 'loc', 'getitem', None}, but found: {kind}"
)

if side not in {"left", "right"}:
raise ValueError(
"Invalid value for side kwarg,"
" must be either 'left' or 'right': %s" % (side,)
)

# TODO: Handle errors/missing keys correctly
# Not currently using `kind` argument.
if side == "left":
return self.find_first_value(label, closest=True)
elif side == "right":
Expand Down
20 changes: 3 additions & 17 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def is_monotonic_decreasing(self):
return self._step < 0 or len(self) <= 1

@_cudf_nvtx_annotate
def get_slice_bound(self, label, side, kind=None):
def get_slice_bound(self, label, side):
"""
Calculate slice bound that corresponds to given label.
Returns leftmost (one-past-the-rightmost if ``side=='right'``) position
Expand All @@ -506,20 +506,12 @@ def get_slice_bound(self, label, side, kind=None):
label : int
A valid value in the ``RangeIndex``
side : {'left', 'right'}
kind : Unused
To keep consistency with other index types.
Returns
-------
int
Index of label.
"""
if kind is not None:
warnings.warn(
"'kind' argument in get_slice_bound is deprecated and will be "
"removed in a future version.",
FutureWarning,
)
if side not in {"left", "right"}:
raise ValueError(f"Unrecognized side parameter: {side}")

Expand Down Expand Up @@ -1388,14 +1380,8 @@ def notna(self):
notnull = notna

@_cudf_nvtx_annotate
def get_slice_bound(self, label, side, kind=None):
if kind is not None:
warnings.warn(
"'kind' argument in get_slice_bound is deprecated and will be "
"removed in a future version.",
FutureWarning,
)
return self._values.get_slice_bound(label, side, kind)
def get_slice_bound(self, label, side):
return self._values.get_slice_bound(label, side)

def _is_numeric(self):
return False
Expand Down
44 changes: 15 additions & 29 deletions python/cudf/cudf/tests/test_monotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
RangeIndex,
StringIndex,
)
from cudf.testing._utils import assert_eq, expect_warning_if
from cudf.testing._utils import assert_eq


@pytest.mark.parametrize("testrange", [(10, 20, 1), (0, -10, -1), (5, 5, 1)])
Expand Down Expand Up @@ -222,15 +222,12 @@ def test_multiindex_tuples(testarr):
],
)
@pytest.mark.parametrize("side", ["left", "right"])
@pytest.mark.parametrize("kind", ["loc", "getitem", None])
def test_get_slice_bound(testlist, side, kind):
def test_get_slice_bound(testlist, side):
index = GenericIndex(testlist)
index_pd = pd.Index(testlist)
for label in testlist:
with pytest.warns(FutureWarning):
expect = index_pd.get_slice_bound(label, side, kind)
with expect_warning_if(kind is not None, FutureWarning):
got = index.get_slice_bound(label, side, kind)
expect = index_pd.get_slice_bound(label, side)
got = index.get_slice_bound(label, side)
assert got == expect


Expand All @@ -240,16 +237,13 @@ def test_get_slice_bound(testlist, side, kind):
[[-1, 0, 5, 10, 11], [-1, 0, 1, 2], [2, 3, 4, 5], [-1, 0, 1], [2, 3, 4]],
)
@pytest.mark.parametrize("side", ["left", "right"])
@pytest.mark.parametrize("kind", ["getitem", "loc"])
def test_rangeindex_get_slice_bound_basic(bounds, indices, side, kind):
def test_rangeindex_get_slice_bound_basic(bounds, indices, side):
start, stop = bounds
pd_index = pd.RangeIndex(start, stop)
cudf_index = RangeIndex(start, stop)
for idx in indices:
with pytest.warns(FutureWarning):
expect = pd_index.get_slice_bound(idx, side, kind)
with expect_warning_if(kind is not None, FutureWarning):
got = cudf_index.get_slice_bound(idx, side, kind)
expect = pd_index.get_slice_bound(idx, side)
got = cudf_index.get_slice_bound(idx, side)
assert expect == got


Expand All @@ -262,31 +256,25 @@ def test_rangeindex_get_slice_bound_basic(bounds, indices, side, kind):
[3, 8, 13, 18, 20, 15, 10, 5, -1, 0, 19, 21, 6, 11, 17],
)
@pytest.mark.parametrize("side", ["left", "right"])
@pytest.mark.parametrize("kind", ["getitem", "loc"])
def test_rangeindex_get_slice_bound_step(bounds, label, side, kind):
def test_rangeindex_get_slice_bound_step(bounds, label, side):
start, stop, step = bounds
pd_index = pd.RangeIndex(start, stop, step)
cudf_index = RangeIndex(start, stop, step)

with pytest.warns(FutureWarning):
expect = pd_index.get_slice_bound(label, side, kind)
with expect_warning_if(kind is not None, FutureWarning):
got = cudf_index.get_slice_bound(label, side, kind)
expect = pd_index.get_slice_bound(label, side)
got = cudf_index.get_slice_bound(label, side)
assert expect == got


@pytest.mark.parametrize("label", [1, 3, 5, 7, 9, 11])
@pytest.mark.parametrize("side", ["left", "right"])
@pytest.mark.parametrize("kind", ["loc", "getitem", None])
def test_get_slice_bound_missing(label, side, kind):
def test_get_slice_bound_missing(label, side):
mylist = [2, 4, 6, 8, 10]
index = GenericIndex(mylist)
index_pd = pd.Index(mylist)

with pytest.warns(FutureWarning):
expect = index_pd.get_slice_bound(label, side, kind)
with expect_warning_if(kind is not None, FutureWarning):
got = index.get_slice_bound(label, side, kind)
expect = index_pd.get_slice_bound(label, side)
got = index.get_slice_bound(label, side)
assert got == expect


Expand All @@ -299,10 +287,8 @@ def test_get_slice_bound_missing_str(label, side):
mylist = ["b", "d", "f"]
index = GenericIndex(mylist)
index_pd = pd.Index(mylist)
with pytest.warns(FutureWarning):
got = index.get_slice_bound(label, side, "getitem")
with pytest.warns(FutureWarning):
expect = index_pd.get_slice_bound(label, side, "getitem")
got = index.get_slice_bound(label, side)
expect = index_pd.get_slice_bound(label, side)
assert got == expect


Expand Down

0 comments on commit 7ec76b7

Please sign in to comment.