Skip to content

Commit f8607aa

Browse files
committed
Add version-dependent logic to add kind argument where needed in tests
1 parent 381a6c2 commit f8607aa

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

xarray/tests/test_cftimeindex.py

Lines changed: 41 additions & 12 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
@@ -346,57 +347,85 @@ def test_get_loc(date_type, index):
346347

347348
@requires_cftime
348349
def test_get_slice_bound(date_type, index):
349-
result = index.get_slice_bound("0001", "left")
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)
350359
expected = 0
351360
assert result == expected
352361

353-
result = index.get_slice_bound("0001", "right")
362+
result = index.get_slice_bound("0001", "right", *kind_args)
354363
expected = 2
355364
assert result == expected
356365

357-
result = index.get_slice_bound(date_type(1, 3, 1), "left")
366+
result = index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args)
358367
expected = 2
359368
assert result == expected
360369

361-
result = index.get_slice_bound(date_type(1, 3, 1), "right")
370+
result = index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args)
362371
expected = 2
363372
assert result == expected
364373

365374

366375
@requires_cftime
367376
def test_get_slice_bound_decreasing_index(date_type, monotonic_decreasing_index):
368-
result = monotonic_decreasing_index.get_slice_bound("0001", "left")
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)
369386
expected = 2
370387
assert result == expected
371388

372-
result = monotonic_decreasing_index.get_slice_bound("0001", "right")
389+
result = monotonic_decreasing_index.get_slice_bound("0001", "right", *kind_args)
373390
expected = 4
374391
assert result == expected
375392

376-
result = monotonic_decreasing_index.get_slice_bound(date_type(1, 3, 1), "left")
393+
result = monotonic_decreasing_index.get_slice_bound(
394+
date_type(1, 3, 1), "left", *kind_args
395+
)
377396
expected = 2
378397
assert result == expected
379398

380-
result = monotonic_decreasing_index.get_slice_bound(date_type(1, 3, 1), "right")
399+
result = monotonic_decreasing_index.get_slice_bound(
400+
date_type(1, 3, 1), "right", *kind_args
401+
)
381402
expected = 2
382403
assert result == expected
383404

384405

385406
@requires_cftime
386407
def test_get_slice_bound_length_one_index(date_type, length_one_index):
387-
result = length_one_index.get_slice_bound("0001", "left")
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)
388417
expected = 0
389418
assert result == expected
390419

391-
result = length_one_index.get_slice_bound("0001", "right")
420+
result = length_one_index.get_slice_bound("0001", "right", *kind_args)
392421
expected = 1
393422
assert result == expected
394423

395-
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left")
424+
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "left", *kind_args)
396425
expected = 1
397426
assert result == expected
398427

399-
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right")
428+
result = length_one_index.get_slice_bound(date_type(1, 3, 1), "right", *kind_args)
400429
expected = 1
401430
assert result == expected
402431

0 commit comments

Comments
 (0)