@@ -554,6 +554,23 @@ def test_intersection(self):
554
554
result = idx1 .intersection (idx2 )
555
555
self .assertTrue (result .equals (expected ))
556
556
557
+ # preserve names
558
+ first = self .strIndex [5 :20 ]
559
+ second = self .strIndex [:10 ]
560
+ first .name = 'A'
561
+ second .name = 'A'
562
+ intersect = first .intersection (second )
563
+ self .assertEqual (intersect .name , 'A' )
564
+
565
+ second .name = 'B'
566
+ intersect = first .intersection (second )
567
+ self .assertIsNone (intersect .name )
568
+
569
+ first .name = None
570
+ second .name = 'B'
571
+ intersect = first .intersection (second )
572
+ self .assertIsNone (intersect .name )
573
+
557
574
def test_union (self ):
558
575
first = self .strIndex [5 :20 ]
559
576
second = self .strIndex [:10 ]
@@ -578,15 +595,51 @@ def test_union(self):
578
595
self .assertIs (union , first )
579
596
580
597
# preserve names
581
- first . name = 'A'
582
- second . name = 'A'
598
+ first = Index ( list ( 'ab' ), name = 'A' )
599
+ second = Index ( list ( 'ab' ), name = 'B' )
583
600
union = first .union (second )
584
- self .assertEqual (union .name , 'A' )
601
+ self .assertIsNone (union .name )
585
602
586
- second .name = 'B'
603
+ first = Index (list ('ab' ), name = 'A' )
604
+ second = Index ([], name = 'B' )
587
605
union = first .union (second )
588
606
self .assertIsNone (union .name )
589
607
608
+ first = Index ([], name = 'A' )
609
+ second = Index (list ('ab' ), name = 'B' )
610
+ union = first .union (second )
611
+ self .assertIsNone (union .name )
612
+
613
+ first = Index (list ('ab' ))
614
+ second = Index (list ('ab' ), name = 'B' )
615
+ union = first .union (second )
616
+ self .assertEqual (union .name , 'B' )
617
+
618
+ first = Index ([])
619
+ second = Index (list ('ab' ), name = 'B' )
620
+ union = first .union (second )
621
+ self .assertEqual (union .name , 'B' )
622
+
623
+ first = Index (list ('ab' ))
624
+ second = Index ([], name = 'B' )
625
+ union = first .union (second )
626
+ self .assertEqual (union .name , 'B' )
627
+
628
+ first = Index (list ('ab' ), name = 'A' )
629
+ second = Index (list ('ab' ))
630
+ union = first .union (second )
631
+ self .assertEqual (union .name , 'A' )
632
+
633
+ first = Index (list ('ab' ), name = 'A' )
634
+ second = Index ([])
635
+ union = first .union (second )
636
+ self .assertEqual (union .name , 'A' )
637
+
638
+ first = Index ([], name = 'A' )
639
+ second = Index (list ('ab' ))
640
+ union = first .union (second )
641
+ self .assertEqual (union .name , 'A' )
642
+
590
643
def test_add (self ):
591
644
592
645
# - API change GH 8226
0 commit comments