From 9057aa12fbc40b65fc742fcc0da58076b6a139f1 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Mon, 27 Feb 2023 13:28:44 -0800 Subject: [PATCH] Drop kind in get_slice_bound --- python/cudf/cudf/core/_base_index.py | 3 +- python/cudf/cudf/core/column/column.py | 12 ++----- python/cudf/cudf/core/index.py | 22 +++--------- python/cudf/cudf/tests/test_monotonic.py | 46 +++++++++--------------- 4 files changed, 23 insertions(+), 60 deletions(-) diff --git a/python/cudf/cudf/core/_base_index.py b/python/cudf/cudf/core/_base_index.py index 8f8f2afc734..7702c14e566 100644 --- a/python/cudf/cudf/core/_base_index.py +++ b/python/cudf/cudf/core/_base_index.py @@ -1354,7 +1354,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 @@ -1364,7 +1364,6 @@ def get_slice_bound(self, label, side, kind=None): ---------- label : object side : {'left', 'right'} - kind : {'ix', 'loc', 'getitem'} Returns ------- diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index b5f36aa3594..47918e62789 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -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 @@ -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": diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 324db416be4..d9c32b6ffb1 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. from __future__ import annotations @@ -510,7 +510,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 @@ -521,20 +521,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}") @@ -1413,14 +1405,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 diff --git a/python/cudf/cudf/tests/test_monotonic.py b/python/cudf/cudf/tests/test_monotonic.py index f4e8b80342a..8d8cdc78f6e 100644 --- a/python/cudf/cudf/tests/test_monotonic.py +++ b/python/cudf/cudf/tests/test_monotonic.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. """ Tests related to is_unique and is_monotonic attributes @@ -16,7 +16,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)]) @@ -261,15 +261,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 @@ -279,16 +276,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 @@ -301,31 +295,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 @@ -338,10 +326,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