|
6 | 6 | from pandas.errors import InvalidIndexError
|
7 | 7 |
|
8 | 8 | import pandas as pd
|
9 |
| -from pandas import DatetimeIndex, Index, Timestamp, date_range, notna |
| 9 | +from pandas import DatetimeIndex, Index, Timestamp, bdate_range, date_range, notna |
10 | 10 | import pandas._testing as tm
|
11 | 11 |
|
12 | 12 | from pandas.tseries.offsets import BDay, CDay
|
@@ -665,3 +665,43 @@ def test_get_value(self):
|
665 | 665 | with tm.assert_produces_warning(FutureWarning):
|
666 | 666 | result = dti.get_value(ser, key.to_datetime64())
|
667 | 667 | assert result == 7
|
| 668 | + |
| 669 | + |
| 670 | +class TestGetSliceBounds: |
| 671 | + @pytest.mark.parametrize("box", [date, datetime, Timestamp]) |
| 672 | + @pytest.mark.parametrize("kind", ["getitem", "loc", None]) |
| 673 | + @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)]) |
| 674 | + def test_get_slice_bounds_datetime_within( |
| 675 | + self, box, kind, side, expected, tz_aware_fixture |
| 676 | + ): |
| 677 | + # GH 35690 |
| 678 | + index = bdate_range("2000-01-03", "2000-02-11").tz_localize(tz_aware_fixture) |
| 679 | + result = index.get_slice_bound( |
| 680 | + box(year=2000, month=1, day=7), kind=kind, side=side |
| 681 | + ) |
| 682 | + assert result == expected |
| 683 | + |
| 684 | + @pytest.mark.parametrize("box", [date, datetime, Timestamp]) |
| 685 | + @pytest.mark.parametrize("kind", ["getitem", "loc", None]) |
| 686 | + @pytest.mark.parametrize("side", ["left", "right"]) |
| 687 | + @pytest.mark.parametrize("year, expected", [(1999, 0), (2020, 30)]) |
| 688 | + def test_get_slice_bounds_datetime_outside( |
| 689 | + self, box, kind, side, year, expected, tz_aware_fixture |
| 690 | + ): |
| 691 | + # GH 35690 |
| 692 | + index = bdate_range("2000-01-03", "2000-02-11").tz_localize(tz_aware_fixture) |
| 693 | + result = index.get_slice_bound( |
| 694 | + box(year=year, month=1, day=7), kind=kind, side=side |
| 695 | + ) |
| 696 | + assert result == expected |
| 697 | + |
| 698 | + @pytest.mark.parametrize("box", [date, datetime, Timestamp]) |
| 699 | + @pytest.mark.parametrize("kind", ["getitem", "loc", None]) |
| 700 | + def test_slice_datetime_locs(self, box, kind, tz_aware_fixture): |
| 701 | + # GH 34077 |
| 702 | + index = DatetimeIndex(["2010-01-01", "2010-01-03"]).tz_localize( |
| 703 | + tz_aware_fixture |
| 704 | + ) |
| 705 | + result = index.slice_locs(box(2010, 1, 1), box(2010, 1, 2)) |
| 706 | + expected = (0, 1) |
| 707 | + assert result == expected |
0 commit comments