|
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
|
@@ -346,57 +347,85 @@ def test_get_loc(date_type, index):
|
346 | 347 |
|
347 | 348 | @requires_cftime
|
348 | 349 | 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) |
350 | 359 | expected = 0
|
351 | 360 | assert result == expected
|
352 | 361 |
|
353 |
| - result = index.get_slice_bound("0001", "right") |
| 362 | + result = index.get_slice_bound("0001", "right", *kind_args) |
354 | 363 | expected = 2
|
355 | 364 | assert result == expected
|
356 | 365 |
|
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) |
358 | 367 | expected = 2
|
359 | 368 | assert result == expected
|
360 | 369 |
|
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) |
362 | 371 | expected = 2
|
363 | 372 | assert result == expected
|
364 | 373 |
|
365 | 374 |
|
366 | 375 | @requires_cftime
|
367 | 376 | 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) |
369 | 386 | expected = 2
|
370 | 387 | assert result == expected
|
371 | 388 |
|
372 |
| - result = monotonic_decreasing_index.get_slice_bound("0001", "right") |
| 389 | + result = monotonic_decreasing_index.get_slice_bound("0001", "right", *kind_args) |
373 | 390 | expected = 4
|
374 | 391 | assert result == expected
|
375 | 392 |
|
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 | + ) |
377 | 396 | expected = 2
|
378 | 397 | assert result == expected
|
379 | 398 |
|
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 | + ) |
381 | 402 | expected = 2
|
382 | 403 | assert result == expected
|
383 | 404 |
|
384 | 405 |
|
385 | 406 | @requires_cftime
|
386 | 407 | 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) |
388 | 417 | expected = 0
|
389 | 418 | assert result == expected
|
390 | 419 |
|
391 |
| - result = length_one_index.get_slice_bound("0001", "right") |
| 420 | + result = length_one_index.get_slice_bound("0001", "right", *kind_args) |
392 | 421 | expected = 1
|
393 | 422 | assert result == expected
|
394 | 423 |
|
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) |
396 | 425 | expected = 1
|
397 | 426 | assert result == expected
|
398 | 427 |
|
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) |
400 | 429 | expected = 1
|
401 | 430 | assert result == expected
|
402 | 431 |
|
|
0 commit comments