Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ Internal Changes
By `Jimmy Westling <https://github.com/illviljan>`_.
- Use isort's `float_to_top` config. (:pull:`5695`).
By `Maximilian Roos <https://github.com/max-sixty>`_.
- 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 <https://github.com/spencerkclark>`_.
- 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`)
Expand Down
58 changes: 40 additions & 18 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from distutils.version import LooseVersion
from textwrap import dedent

import numpy as np
Expand Down Expand Up @@ -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

Expand Down