|
1 | 1 | from datetime import timedelta
|
| 2 | +from distutils.version import LooseVersion |
2 | 3 | from textwrap import dedent
|
3 | 4 |
|
4 | 5 | import numpy as np
|
@@ -345,65 +346,86 @@ def test_get_loc(date_type, index):
|
345 | 346 |
|
346 | 347 |
|
347 | 348 | @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) |
351 | 359 | expected = 0
|
352 | 360 | assert result == expected
|
353 | 361 |
|
354 |
| - result = index.get_slice_bound("0001", "right", kind) |
| 362 | + result = index.get_slice_bound("0001", "right", *kind_args) |
355 | 363 | expected = 2
|
356 | 364 | assert result == expected
|
357 | 365 |
|
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) |
359 | 367 | expected = 2
|
360 | 368 | assert result == expected
|
361 | 369 |
|
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) |
363 | 371 | expected = 2
|
364 | 372 | assert result == expected
|
365 | 373 |
|
366 | 374 |
|
367 | 375 | @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) |
371 | 386 | expected = 2
|
372 | 387 | assert result == expected
|
373 | 388 |
|
374 |
| - result = monotonic_decreasing_index.get_slice_bound("0001", "right", kind) |
| 389 | + result = monotonic_decreasing_index.get_slice_bound("0001", "right", *kind_args) |
375 | 390 | expected = 4
|
376 | 391 | assert result == expected
|
377 | 392 |
|
378 | 393 | result = monotonic_decreasing_index.get_slice_bound(
|
379 |
| - date_type(1, 3, 1), "left", kind |
| 394 | + date_type(1, 3, 1), "left", *kind_args |
380 | 395 | )
|
381 | 396 | expected = 2
|
382 | 397 | assert result == expected
|
383 | 398 |
|
384 | 399 | result = monotonic_decreasing_index.get_slice_bound(
|
385 |
| - date_type(1, 3, 1), "right", kind |
| 400 | + date_type(1, 3, 1), "right", *kind_args |
386 | 401 | )
|
387 | 402 | expected = 2
|
388 | 403 | assert result == expected
|
389 | 404 |
|
390 | 405 |
|
391 | 406 | @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) |
395 | 417 | expected = 0
|
396 | 418 | assert result == expected
|
397 | 419 |
|
398 |
| - result = length_one_index.get_slice_bound("0001", "right", kind) |
| 420 | + result = length_one_index.get_slice_bound("0001", "right", *kind_args) |
399 | 421 | expected = 1
|
400 | 422 | assert result == expected
|
401 | 423 |
|
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) |
403 | 425 | expected = 1
|
404 | 426 | assert result == expected
|
405 | 427 |
|
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) |
407 | 429 | expected = 1
|
408 | 430 | assert result == expected
|
409 | 431 |
|
|
0 commit comments