Skip to content

Commit 69dec51

Browse files
Remove use of deprecated kind argument in CFTimeIndex tests (#5723)
1 parent ea28861 commit 69dec51

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ Internal Changes
106106
By `Jimmy Westling <https://github.com/illviljan>`_.
107107
- Use isort's `float_to_top` config. (:pull:`5695`).
108108
By `Maximilian Roos <https://github.com/max-sixty>`_.
109+
- Remove use of the deprecated ``kind`` argument in
110+
:py:meth:`pandas.Index.get_slice_bound` inside :py:class:`xarray.CFTimeIndex`
111+
tests (:pull:`5723`). By `Spencer Clark <https://github.com/spencerkclark>`_.
109112
- Refactor `xarray.core.duck_array_ops` to no longer special-case dispatching to
110113
dask versions of functions when acting on dask arrays, instead relying numpy
111114
and dask's adherence to NEP-18 to dispatch automatically. (:pull:`5571`)

xarray/tests/test_cftimeindex.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import timedelta
2+
from distutils.version import LooseVersion
23
from textwrap import dedent
34

45
import numpy as np
@@ -345,65 +346,86 @@ def test_get_loc(date_type, index):
345346

346347

347348
@requires_cftime
348-
@pytest.mark.parametrize("kind", ["loc", "getitem"])
349-
def test_get_slice_bound(date_type, index, kind):
350-
result = index.get_slice_bound("0001", "left", kind)
349+
def test_get_slice_bound(date_type, index):
350+
# The kind argument is required in earlier versions of pandas even though it
351+
# is not used by CFTimeIndex. This logic can be removed once our minimum
352+
# version of pandas is at least 1.3.
353+
if LooseVersion(pd.__version__) < LooseVersion("1.3"):
354+
kind_args = ("getitem",)
355+
else:
356+
kind_args = ()
357+
358+
result = index.get_slice_bound("0001", "left", *kind_args)
351359
expected = 0
352360
assert result == expected
353361

354-
result = index.get_slice_bound("0001", "right", kind)
362+
result = index.get_slice_bound("0001", "right", *kind_args)
355363
expected = 2
356364
assert result == expected
357365

358-
result = index.get_slice_bound(date_type(1, 3, 1), "left", kind)
366+
result = index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args)
359367
expected = 2
360368
assert result == expected
361369

362-
result = index.get_slice_bound(date_type(1, 3, 1), "right", kind)
370+
result = index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args)
363371
expected = 2
364372
assert result == expected
365373

366374

367375
@requires_cftime
368-
@pytest.mark.parametrize("kind", ["loc", "getitem"])
369-
def test_get_slice_bound_decreasing_index(date_type, monotonic_decreasing_index, kind):
370-
result = monotonic_decreasing_index.get_slice_bound("0001", "left", kind)
376+
def test_get_slice_bound_decreasing_index(date_type, monotonic_decreasing_index):
377+
# The kind argument is required in earlier versions of pandas even though it
378+
# is not used by CFTimeIndex. This logic can be removed once our minimum
379+
# version of pandas is at least 1.3.
380+
if LooseVersion(pd.__version__) < LooseVersion("1.3"):
381+
kind_args = ("getitem",)
382+
else:
383+
kind_args = ()
384+
385+
result = monotonic_decreasing_index.get_slice_bound("0001", "left", *kind_args)
371386
expected = 2
372387
assert result == expected
373388

374-
result = monotonic_decreasing_index.get_slice_bound("0001", "right", kind)
389+
result = monotonic_decreasing_index.get_slice_bound("0001", "right", *kind_args)
375390
expected = 4
376391
assert result == expected
377392

378393
result = monotonic_decreasing_index.get_slice_bound(
379-
date_type(1, 3, 1), "left", kind
394+
date_type(1, 3, 1), "left", *kind_args
380395
)
381396
expected = 2
382397
assert result == expected
383398

384399
result = monotonic_decreasing_index.get_slice_bound(
385-
date_type(1, 3, 1), "right", kind
400+
date_type(1, 3, 1), "right", *kind_args
386401
)
387402
expected = 2
388403
assert result == expected
389404

390405

391406
@requires_cftime
392-
@pytest.mark.parametrize("kind", ["loc", "getitem"])
393-
def test_get_slice_bound_length_one_index(date_type, length_one_index, kind):
394-
result = length_one_index.get_slice_bound("0001", "left", kind)
407+
def test_get_slice_bound_length_one_index(date_type, length_one_index):
408+
# The kind argument is required in earlier versions of pandas even though it
409+
# is not used by CFTimeIndex. This logic can be removed once our minimum
410+
# version of pandas is at least 1.3.
411+
if LooseVersion(pd.__version__) <= LooseVersion("1.3"):
412+
kind_args = ("getitem",)
413+
else:
414+
kind_args = ()
415+
416+
result = length_one_index.get_slice_bound("0001", "left", *kind_args)
395417
expected = 0
396418
assert result == expected
397419

398-
result = length_one_index.get_slice_bound("0001", "right", kind)
420+
result = length_one_index.get_slice_bound("0001", "right", *kind_args)
399421
expected = 1
400422
assert result == expected
401423

402-
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left", kind)
424+
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args)
403425
expected = 1
404426
assert result == expected
405427

406-
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right", kind)
428+
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args)
407429
expected = 1
408430
assert result == expected
409431

0 commit comments

Comments
 (0)