@@ -581,101 +581,61 @@ def test_union_noncomparable(self):
581
581
tm .assert_index_equal (result , expected )
582
582
583
583
@pytest .fixture
584
- def union_inputs (self ):
585
- """Inputs for RangeIndex.union tests"""
584
+ def union_fixture (self ):
585
+ """Inputs and expected outputs for RangeIndex.union tests"""
586
586
RI = RangeIndex
587
587
I64 = Int64Index
588
588
589
- inputs = [(RI (0 , 10 , 1 ), RI (0 , 10 , 1 )),
590
- (RI (0 , 10 , 1 ), RI (5 , 20 , 1 )),
591
- (RI (0 , 10 , 1 ), RI (10 , 20 , 1 )),
592
- (RI (0 , - 10 , - 1 ), RI (0 , - 10 , - 1 )),
593
- (RI (0 , - 10 , - 1 ), RI (- 10 , - 20 , - 1 )),
594
- (RI (0 , 10 , 2 ), RI (1 , 10 , 2 )),
595
- (RI (0 , 11 , 2 ), RI (1 , 12 , 2 )),
596
- (RI (0 , 21 , 4 ), RI (- 2 , 24 , 4 )),
597
- (RI (0 , - 20 , - 2 ), RI (- 1 , - 21 , - 2 )),
598
- (RI (0 , 100 , 5 ), RI (0 , 100 , 20 )),
599
- (RI (0 , - 100 , - 5 ), RI (5 , - 100 , - 20 )),
600
- (RI (0 , - 11 , - 1 ), RI (1 , - 12 , - 4 )),
601
- (RI (0 ), RI (0 )),
602
- (RI (0 , - 10 , - 2 ), RI (0 )),
603
- (RI (0 , 100 , 2 ), RI (100 , 150 , 200 )),
604
- (RI (0 , - 100 , - 2 ), RI (- 100 , 50 , 102 )),
605
- (RI (0 , - 100 , - 1 ), RI (0 , - 50 , - 3 )),
606
- (RI (0 , 1 , 1 ), RI (5 , 6 , 10 )),
607
- (RI (0 , 10 , 5 ), RI (- 5 , - 6 , - 20 )),
608
- (RI (0 , 3 , 1 ), RI (4 , 5 , 1 )),
609
- (RI (0 , 10 , 1 ), I64 ([])),
610
- (RI (0 ), I64 ([1 , 5 , 6 ]))]
611
-
612
- return inputs
613
-
614
- def test_union_sorted (self , union_inputs ):
615
- RI = RangeIndex
616
- I64 = Int64Index
617
-
618
- expected = [RI (0 , 10 , 1 ),
619
- RI (0 , 20 , 1 ),
620
- RI (0 , 20 , 1 ),
621
- RI (0 , - 10 , - 1 ),
622
- RI (- 19 , 1 , 1 ),
623
- RI (0 , 10 , 1 ),
624
- RI (0 , 12 , 1 ),
625
- RI (- 2 , 24 , 2 ),
626
- RI (- 19 , 1 , 1 ),
627
- RI (0 , 100 , 5 ),
628
- RI (- 95 , 10 , 5 ),
629
- RI (- 11 , 2 , 1 ),
630
- RI (0 ),
631
- RI (0 , - 10 , - 2 ),
632
- RI (0 , 102 , 2 ),
633
- RI (- 100 , 4 , 2 ),
634
- RI (- 99 , 1 , 1 ),
635
- RI (0 , 6 , 5 ),
636
- RI (- 5 , 10 , 5 ),
637
- I64 ([0 , 1 , 2 , 4 ]),
638
- RI (0 , 10 , 1 ),
639
- I64 ([1 , 5 , 6 ])]
640
-
641
- for ((idx1 , idx2 ), expected_sorted ) in zip (union_inputs , expected ):
642
- res1 = idx1 .union (idx2 )
589
+ return [(RI (0 , 10 , 1 ), RI (0 , 10 , 1 ), RI (0 , 10 , 1 ), RI (0 , 10 , 1 )),
590
+ (RI (0 , 10 , 1 ), RI (5 , 20 , 1 ), RI (0 , 20 , 1 ), I64 (range (20 ))),
591
+ (RI (0 , 10 , 1 ), RI (10 , 20 , 1 ), RI (0 , 20 , 1 ), I64 (range (20 ))),
592
+ (RI (0 , - 10 , - 1 ), RI (0 , - 10 , - 1 ), RI (0 , - 10 , - 1 ),
593
+ RI (0 , - 10 , - 1 )),
594
+ (RI (0 , - 10 , - 1 ), RI (- 10 , - 20 , - 1 ), RI (- 19 , 1 , 1 ),
595
+ I64 (range (0 , - 20 , - 1 ))),
596
+ (RI (0 , 10 , 2 ), RI (1 , 10 , 2 ), RI (0 , 10 , 1 ),
597
+ I64 (list (range (0 , 10 , 2 )) + list (range (1 , 10 , 2 )))),
598
+ (RI (0 , 11 , 2 ), RI (1 , 12 , 2 ), RI (0 , 12 , 1 ),
599
+ I64 (list (range (0 , 11 , 2 )) + list (range (1 , 12 , 2 )))),
600
+ (RI (0 , 21 , 4 ), RI (- 2 , 24 , 4 ), RI (- 2 , 24 , 2 ),
601
+ I64 (list (range (0 , 21 , 4 )) + list (range (- 2 , 24 , 4 )))),
602
+ (RI (0 , - 20 , - 2 ), RI (- 1 , - 21 , - 2 ), RI (- 19 , 1 , 1 ),
603
+ I64 (list (range (0 , - 20 , - 2 )) + list (range (- 1 , - 21 , - 2 )))),
604
+ (RI (0 , 100 , 5 ), RI (0 , 100 , 20 ), RI (0 , 100 , 5 ),
605
+ I64 (range (0 , 100 , 5 ))),
606
+ (RI (0 , - 100 , - 5 ), RI (5 , - 100 , - 20 ), RI (- 95 , 10 , 5 ),
607
+ I64 (list (range (0 , - 100 , - 5 )) + [5 ])),
608
+ (RI (0 , - 11 , - 1 ), RI (1 , - 12 , - 4 ), RI (- 11 , 2 , 1 ),
609
+ I64 (list (range (0 , - 11 , - 1 )) + [1 , - 11 ])),
610
+ (RI (0 ), RI (0 ), RI (0 ), RI (0 )),
611
+ (RI (0 , - 10 , - 2 ), RI (0 ), RI (0 , - 10 , - 2 ), RI (0 , - 10 , - 2 )),
612
+ (RI (0 , 100 , 2 ), RI (100 , 150 , 200 ), RI (0 , 102 , 2 ),
613
+ I64 (range (0 , 102 , 2 ))),
614
+ (RI (0 , - 100 , - 2 ), RI (- 100 , 50 , 102 ), RI (- 100 , 4 , 2 ),
615
+ I64 (list (range (0 , - 100 , - 2 )) + [- 100 , 2 ])),
616
+ (RI (0 , - 100 , - 1 ), RI (0 , - 50 , - 3 ), RI (- 99 , 1 , 1 ),
617
+ I64 (list (range (0 , - 100 , - 1 )))),
618
+ (RI (0 , 1 , 1 ), RI (5 , 6 , 10 ), RI (0 , 6 , 5 ), I64 ([0 , 5 ])),
619
+ (RI (0 , 10 , 5 ), RI (- 5 , - 6 , - 20 ), RI (- 5 , 10 , 5 ),
620
+ I64 ([0 , 5 , - 5 ])),
621
+ (RI (0 , 3 , 1 ), RI (4 , 5 , 1 ), I64 ([0 , 1 , 2 , 4 ]),
622
+ I64 ([0 , 1 , 2 , 4 ])),
623
+ (RI (0 , 10 , 1 ), I64 ([]), RI (0 , 10 , 1 ), RI (0 , 10 , 1 )),
624
+ (RI (0 ), I64 ([1 , 5 , 6 ]), I64 ([1 , 5 , 6 ]), I64 ([1 , 5 , 6 ]))]
625
+
626
+ def test_union_sorted (self , union_fixture ):
627
+
628
+ for (idx1 , idx2 , expected_sorted , expected_not_sorted ) in union_fixture :
629
+ res1 = idx1 .union (idx2 , sort = None )
643
630
tm .assert_index_equal (res1 , expected_sorted , exact = True )
644
- res2 = idx2 .union (idx1 )
645
- res3 = idx1 ._int64index .union (idx2 )
646
- tm .assert_index_equal (res2 , expected_sorted , exact = True )
647
- tm .assert_index_equal (res3 , expected_sorted )
648
631
649
- def test_union_notsorted (self , union_inputs ):
650
- RI = RangeIndex
651
- I64 = Int64Index
652
-
653
- expected = [RI (0 , 10 , 1 ),
654
- I64 (range (20 )),
655
- I64 (range (20 )),
656
- RI (0 , - 10 , - 1 ),
657
- I64 (range (0 , - 20 , - 1 )),
658
- I64 (list (range (0 , 10 , 2 )) + list (range (1 , 10 , 2 ))),
659
- I64 (list (range (0 , 11 , 2 )) + list (range (1 , 12 , 2 ))),
660
- I64 (list (range (0 , 21 , 4 )) + list (range (- 2 , 24 , 4 ))),
661
- I64 (list (range (0 , - 20 , - 2 )) + list (range (- 1 , - 21 , - 2 ))),
662
- I64 (range (0 , 100 , 5 )),
663
- I64 (list (range (0 , - 100 , - 5 )) + [5 ]),
664
- I64 (list (range (0 , - 11 , - 1 )) + [1 , - 11 ]),
665
- RI (0 ),
666
- RI (0 , - 10 , - 2 ),
667
- I64 (range (0 , 102 , 2 )),
668
- I64 (list (range (0 , - 100 , - 2 )) + [- 100 , 2 ]),
669
- I64 (list (range (0 , - 100 , - 1 ))),
670
- I64 ([0 , 5 ]),
671
- I64 ([0 , 5 , - 5 ]),
672
- I64 ([0 , 1 , 2 , 4 ]),
673
- RI (0 , 10 , 1 ),
674
- I64 ([1 , 5 , 6 ])]
675
-
676
- for ((idx1 , idx2 ), expected_notsorted ) in zip (union_inputs , expected ):
677
632
res1 = idx1 .union (idx2 , sort = False )
678
- tm .assert_index_equal (res1 , expected_notsorted , exact = True )
633
+ tm .assert_index_equal (res1 , expected_not_sorted , exact = True )
634
+
635
+ res2 = idx2 .union (idx1 , sort = None )
636
+ res3 = idx1 ._int64index .union (idx2 , sort = None )
637
+ tm .assert_index_equal (res2 , expected_sorted , exact = True )
638
+ tm .assert_index_equal (res3 , expected_sorted )
679
639
680
640
def test_nbytes (self ):
681
641
0 commit comments