Skip to content

Commit d210dc1

Browse files
committed
add tests
1 parent 66d465b commit d210dc1

File tree

1 file changed

+62
-23
lines changed

1 file changed

+62
-23
lines changed

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -548,59 +548,81 @@ def test_range_closed(self, freq):
548548
begin = datetime(2011, 1, 1)
549549
end = datetime(2014, 1, 1)
550550

551-
closed = date_range(begin, end, inclusive="both", freq=freq)
551+
both = date_range(begin, end, inclusive="both", freq=freq)
552552
left = date_range(begin, end, inclusive="left", freq=freq)
553553
right = date_range(begin, end, inclusive="right", freq=freq)
554+
neither = date_range(begin, end, inclusive="neither", freq=freq)
555+
554556
expected_left = left
555557
expected_right = right
558+
expected_neither = neither
556559

557-
if end == closed[-1]:
558-
expected_left = closed[:-1]
559-
if begin == closed[0]:
560-
expected_right = closed[1:]
560+
if end == both[-1]:
561+
expected_left = both[:-1]
562+
if begin == both[0]:
563+
expected_right = both[1:]
564+
if end == both[-1] and begin == both[0]:
565+
expected_neither = both[1:-1]
561566

562567
tm.assert_index_equal(expected_left, left)
563568
tm.assert_index_equal(expected_right, right)
569+
tm.assert_index_equal(expected_neither, neither)
564570

565571
def test_range_closed_with_tz_aware_start_end(self):
566572
# GH12409, GH12684
567573
begin = Timestamp("2011/1/1", tz="US/Eastern")
568574
end = Timestamp("2014/1/1", tz="US/Eastern")
569575

570576
for freq in ["1D", "3D", "2M", "7W", "3H", "A"]:
571-
closed = date_range(begin, end, inclusive="both", freq=freq)
577+
both = date_range(begin, end, inclusive="both", freq=freq)
572578
left = date_range(begin, end, inclusive="left", freq=freq)
573579
right = date_range(begin, end, inclusive="right", freq=freq)
580+
neither = date_range(begin, end, inclusive="neither", freq=freq)
581+
574582
expected_left = left
575583
expected_right = right
584+
expected_neither = neither
576585

577-
if end == closed[-1]:
578-
expected_left = closed[:-1]
579-
if begin == closed[0]:
580-
expected_right = closed[1:]
586+
if end == both[-1]:
587+
expected_left = both[:-1]
588+
if begin == both[0]:
589+
expected_right = both[1:]
590+
if end == both[-1] and begin == both[0]:
591+
expected_neither = both[1:-1]
581592

582593
tm.assert_index_equal(expected_left, left)
583594
tm.assert_index_equal(expected_right, right)
595+
tm.assert_index_equal(expected_neither, neither)
584596

585597
begin = Timestamp("2011/1/1")
586598
end = Timestamp("2014/1/1")
587599
begintz = Timestamp("2011/1/1", tz="US/Eastern")
588600
endtz = Timestamp("2014/1/1", tz="US/Eastern")
589601

590602
for freq in ["1D", "3D", "2M", "7W", "3H", "A"]:
591-
closed = date_range(begin, end, inclusive="both", freq=freq, tz="US/Eastern")
603+
both = date_range(begin, end, inclusive="both", freq=freq, tz="US/Eastern")
592604
left = date_range(begin, end, inclusive="left", freq=freq, tz="US/Eastern")
593-
right = date_range(begin, end, inclusive="right", freq=freq, tz="US/Eastern")
605+
right = date_range(
606+
begin, end, inclusive="right", freq=freq, tz="US/Eastern"
607+
)
608+
neither = date_range(
609+
begin, end, inclusive="neither", freq=freq, tz="US/Eastern"
610+
)
611+
594612
expected_left = left
595613
expected_right = right
614+
expected_neither = neither
596615

597-
if endtz == closed[-1]:
598-
expected_left = closed[:-1]
599-
if begintz == closed[0]:
600-
expected_right = closed[1:]
616+
if endtz == both[-1]:
617+
expected_left = both[:-1]
618+
if begintz == both[0]:
619+
expected_right = both[1:]
620+
if begintz == both[0] and endtz == both[-1]:
621+
expected_neither = both[1:-1]
601622

602623
tm.assert_index_equal(expected_left, left)
603624
tm.assert_index_equal(expected_right, right)
625+
tm.assert_index_equal(expected_neither, neither)
604626

605627
@pytest.mark.parametrize("inclusive", ["right", "left", "both", "neither"])
606628
def test_range_closed_boundary(self, inclusive):
@@ -614,22 +636,28 @@ def test_range_closed_boundary(self, inclusive):
614636
both_boundary = date_range(
615637
"2015-09-01", "2015-12-01", freq="QS-MAR", inclusive=inclusive
616638
)
617-
expected_right = expected_left = expected_both = both_boundary
639+
neither_boundary = date_range(
640+
"2015-09-11", "2015-09-12", freq="QS-MAR", inclusive=inclusive
641+
)
642+
643+
expected_right = both_boundary
644+
expected_left = both_boundary
645+
expected_both = both_boundary
618646

619647
if inclusive == "right":
620648
expected_left = both_boundary[1:]
621-
if inclusive == "left":
649+
elif inclusive == "left":
622650
expected_right = both_boundary[:-1]
623-
if inclusive == "both":
651+
elif inclusive == "both":
624652
expected_right = both_boundary[1:]
625653
expected_left = both_boundary[:-1]
626-
if inclusive == "neither":
627-
expected_left = both_boundary[1:]
628-
expected_right = both_boundary[:-1]
654+
655+
expected_neither = both_boundary[1:-1]
629656

630657
tm.assert_index_equal(right_boundary, expected_right)
631658
tm.assert_index_equal(left_boundary, expected_left)
632659
tm.assert_index_equal(both_boundary, expected_both)
660+
tm.assert_index_equal(neither_boundary, expected_neither)
633661

634662
def test_years_only(self):
635663
# GH 6961
@@ -682,6 +710,17 @@ def test_negative_non_tick_frequency_descending_dates(self, tz_aware_fixture):
682710
]
683711
tm.assert_index_equal(result, expected)
684712

713+
def test_range_where_start_equal_end(self):
714+
# GH 43394
715+
start = "2021-09-02"
716+
end = "2021-09-02"
717+
right_result = date_range(start=start, end=end, freq="D", inclusive="right")
718+
left_result = date_range(start=start, end=end, freq="D", inclusive="left")
719+
expected = date_range(start=start, end=end, freq="D", inclusive="both")
720+
721+
tm.assert_index_equal(right_result, expected)
722+
tm.assert_index_equal(left_result, expected)
723+
685724

686725
class TestDateRangeTZ:
687726
"""Tests for date_range with timezones"""
@@ -870,7 +909,7 @@ def test_daterange_bug_456(self):
870909
result = rng1.union(rng2)
871910
assert isinstance(result, DatetimeIndex)
872911

873-
@pytest.mark.parametrize("inclusive", ["left", "right"])
912+
@pytest.mark.parametrize("inclusive", ["left", "right", "neither", "both"])
874913
def test_bdays_and_open_boundaries(self, inclusive):
875914
# GH 6673
876915
start = "2018-07-21" # Saturday

0 commit comments

Comments
 (0)