@@ -548,59 +548,81 @@ def test_range_closed(self, freq):
548
548
begin = datetime (2011 , 1 , 1 )
549
549
end = datetime (2014 , 1 , 1 )
550
550
551
- closed = date_range (begin , end , inclusive = "both" , freq = freq )
551
+ both = date_range (begin , end , inclusive = "both" , freq = freq )
552
552
left = date_range (begin , end , inclusive = "left" , freq = freq )
553
553
right = date_range (begin , end , inclusive = "right" , freq = freq )
554
+ neither = date_range (begin , end , inclusive = "neither" , freq = freq )
555
+
554
556
expected_left = left
555
557
expected_right = right
558
+ expected_neither = neither
556
559
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 ]
561
566
562
567
tm .assert_index_equal (expected_left , left )
563
568
tm .assert_index_equal (expected_right , right )
569
+ tm .assert_index_equal (expected_neither , neither )
564
570
565
571
def test_range_closed_with_tz_aware_start_end (self ):
566
572
# GH12409, GH12684
567
573
begin = Timestamp ("2011/1/1" , tz = "US/Eastern" )
568
574
end = Timestamp ("2014/1/1" , tz = "US/Eastern" )
569
575
570
576
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 )
572
578
left = date_range (begin , end , inclusive = "left" , freq = freq )
573
579
right = date_range (begin , end , inclusive = "right" , freq = freq )
580
+ neither = date_range (begin , end , inclusive = "neither" , freq = freq )
581
+
574
582
expected_left = left
575
583
expected_right = right
584
+ expected_neither = neither
576
585
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 ]
581
592
582
593
tm .assert_index_equal (expected_left , left )
583
594
tm .assert_index_equal (expected_right , right )
595
+ tm .assert_index_equal (expected_neither , neither )
584
596
585
597
begin = Timestamp ("2011/1/1" )
586
598
end = Timestamp ("2014/1/1" )
587
599
begintz = Timestamp ("2011/1/1" , tz = "US/Eastern" )
588
600
endtz = Timestamp ("2014/1/1" , tz = "US/Eastern" )
589
601
590
602
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" )
592
604
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
+
594
612
expected_left = left
595
613
expected_right = right
614
+ expected_neither = neither
596
615
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 ]
601
622
602
623
tm .assert_index_equal (expected_left , left )
603
624
tm .assert_index_equal (expected_right , right )
625
+ tm .assert_index_equal (expected_neither , neither )
604
626
605
627
@pytest .mark .parametrize ("inclusive" , ["right" , "left" , "both" , "neither" ])
606
628
def test_range_closed_boundary (self , inclusive ):
@@ -614,22 +636,28 @@ def test_range_closed_boundary(self, inclusive):
614
636
both_boundary = date_range (
615
637
"2015-09-01" , "2015-12-01" , freq = "QS-MAR" , inclusive = inclusive
616
638
)
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
618
646
619
647
if inclusive == "right" :
620
648
expected_left = both_boundary [1 :]
621
- if inclusive == "left" :
649
+ elif inclusive == "left" :
622
650
expected_right = both_boundary [:- 1 ]
623
- if inclusive == "both" :
651
+ elif inclusive == "both" :
624
652
expected_right = both_boundary [1 :]
625
653
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 ]
629
656
630
657
tm .assert_index_equal (right_boundary , expected_right )
631
658
tm .assert_index_equal (left_boundary , expected_left )
632
659
tm .assert_index_equal (both_boundary , expected_both )
660
+ tm .assert_index_equal (neither_boundary , expected_neither )
633
661
634
662
def test_years_only (self ):
635
663
# GH 6961
@@ -682,6 +710,17 @@ def test_negative_non_tick_frequency_descending_dates(self, tz_aware_fixture):
682
710
]
683
711
tm .assert_index_equal (result , expected )
684
712
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
+
685
724
686
725
class TestDateRangeTZ :
687
726
"""Tests for date_range with timezones"""
@@ -870,7 +909,7 @@ def test_daterange_bug_456(self):
870
909
result = rng1 .union (rng2 )
871
910
assert isinstance (result , DatetimeIndex )
872
911
873
- @pytest .mark .parametrize ("inclusive" , ["left" , "right" ])
912
+ @pytest .mark .parametrize ("inclusive" , ["left" , "right" , "neither" , "both" ])
874
913
def test_bdays_and_open_boundaries (self , inclusive ):
875
914
# GH 6673
876
915
start = "2018-07-21" # Saturday
0 commit comments