diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 1ade92f8588..ae66f9d33ae 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -106,6 +106,9 @@ Internal Changes By `Jimmy Westling `_. - Use isort's `float_to_top` config. (:pull:`5695`). By `Maximilian Roos `_. +- Remove use of the deprecated ``kind`` argument in + :py:meth:`pandas.Index.get_slice_bound` inside :py:class:`xarray.CFTimeIndex` + tests (:pull:`5723`). By `Spencer Clark `_. - Refactor `xarray.core.duck_array_ops` to no longer special-case dispatching to dask versions of functions when acting on dask arrays, instead relying numpy and dask's adherence to NEP-18 to dispatch automatically. (:pull:`5571`) diff --git a/xarray/tests/test_cftimeindex.py b/xarray/tests/test_cftimeindex.py index 725b5efee75..619fb0acdc4 100644 --- a/xarray/tests/test_cftimeindex.py +++ b/xarray/tests/test_cftimeindex.py @@ -1,4 +1,5 @@ from datetime import timedelta +from distutils.version import LooseVersion from textwrap import dedent import numpy as np @@ -345,65 +346,86 @@ def test_get_loc(date_type, index): @requires_cftime -@pytest.mark.parametrize("kind", ["loc", "getitem"]) -def test_get_slice_bound(date_type, index, kind): - result = index.get_slice_bound("0001", "left", kind) +def test_get_slice_bound(date_type, index): + # The kind argument is required in earlier versions of pandas even though it + # is not used by CFTimeIndex. This logic can be removed once our minimum + # version of pandas is at least 1.3. + if LooseVersion(pd.__version__) < LooseVersion("1.3"): + kind_args = ("getitem",) + else: + kind_args = () + + result = index.get_slice_bound("0001", "left", *kind_args) expected = 0 assert result == expected - result = index.get_slice_bound("0001", "right", kind) + result = index.get_slice_bound("0001", "right", *kind_args) expected = 2 assert result == expected - result = index.get_slice_bound(date_type(1, 3, 1), "left", kind) + result = index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args) expected = 2 assert result == expected - result = index.get_slice_bound(date_type(1, 3, 1), "right", kind) + result = index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args) expected = 2 assert result == expected @requires_cftime -@pytest.mark.parametrize("kind", ["loc", "getitem"]) -def test_get_slice_bound_decreasing_index(date_type, monotonic_decreasing_index, kind): - result = monotonic_decreasing_index.get_slice_bound("0001", "left", kind) +def test_get_slice_bound_decreasing_index(date_type, monotonic_decreasing_index): + # The kind argument is required in earlier versions of pandas even though it + # is not used by CFTimeIndex. This logic can be removed once our minimum + # version of pandas is at least 1.3. + if LooseVersion(pd.__version__) < LooseVersion("1.3"): + kind_args = ("getitem",) + else: + kind_args = () + + result = monotonic_decreasing_index.get_slice_bound("0001", "left", *kind_args) expected = 2 assert result == expected - result = monotonic_decreasing_index.get_slice_bound("0001", "right", kind) + result = monotonic_decreasing_index.get_slice_bound("0001", "right", *kind_args) expected = 4 assert result == expected result = monotonic_decreasing_index.get_slice_bound( - date_type(1, 3, 1), "left", kind + date_type(1, 3, 1), "left", *kind_args ) expected = 2 assert result == expected result = monotonic_decreasing_index.get_slice_bound( - date_type(1, 3, 1), "right", kind + date_type(1, 3, 1), "right", *kind_args ) expected = 2 assert result == expected @requires_cftime -@pytest.mark.parametrize("kind", ["loc", "getitem"]) -def test_get_slice_bound_length_one_index(date_type, length_one_index, kind): - result = length_one_index.get_slice_bound("0001", "left", kind) +def test_get_slice_bound_length_one_index(date_type, length_one_index): + # The kind argument is required in earlier versions of pandas even though it + # is not used by CFTimeIndex. This logic can be removed once our minimum + # version of pandas is at least 1.3. + if LooseVersion(pd.__version__) <= LooseVersion("1.3"): + kind_args = ("getitem",) + else: + kind_args = () + + result = length_one_index.get_slice_bound("0001", "left", *kind_args) expected = 0 assert result == expected - result = length_one_index.get_slice_bound("0001", "right", kind) + result = length_one_index.get_slice_bound("0001", "right", *kind_args) expected = 1 assert result == expected - result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left", kind) + result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args) expected = 1 assert result == expected - result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right", kind) + result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args) expected = 1 assert result == expected