@@ -36,15 +36,15 @@ def test_zip_descr(self):
36
36
test = zip_descr ((x , x ), flatten = False )
37
37
assert_equal (test ,
38
38
np .dtype ([('' , int ), ('' , int )]))
39
- # Std & flexible-dtype
39
+ # Std & flexible-dtype
40
40
test = zip_descr ((x , z ), flatten = True )
41
41
assert_equal (test ,
42
42
np .dtype ([('' , int ), ('A' , '|S3' ), ('B' , float )]))
43
43
test = zip_descr ((x , z ), flatten = False )
44
44
assert_equal (test ,
45
45
np .dtype ([('' , int ),
46
46
('' , [('A' , '|S3' ), ('B' , float )])]))
47
- # Standard & nested dtype
47
+ # Standard & nested dtype
48
48
test = zip_descr ((x , w ), flatten = True )
49
49
assert_equal (test ,
50
50
np .dtype ([('' , int ),
@@ -259,7 +259,7 @@ def test_standard(self):
259
259
control = np .array ([(1 , 10 ), (2 , 20 ), (- 1 , 30 )],
260
260
dtype = [('f0' , int ), ('f1' , int )])
261
261
assert_equal (test , control )
262
- #
262
+ #
263
263
test = merge_arrays ((x , y ), usemask = True )
264
264
control = ma .array ([(1 , 10 ), (2 , 20 ), (- 1 , 30 )],
265
265
mask = [(0 , 0 ), (0 , 0 ), (1 , 0 )],
@@ -615,6 +615,67 @@ def test_leftouter_join(self):
615
615
dtype = [('a' , int ), ('b' , int ), ('c' , int ), ('d' , int )])
616
616
617
617
618
+ class TestJoinBy2 (TestCase ):
619
+ @classmethod
620
+ def setUp (cls ):
621
+ cls .a = np .array (zip (np .arange (10 ), np .arange (50 , 60 ),
622
+ np .arange (100 , 110 )),
623
+ dtype = [('a' , int ), ('b' , int ), ('c' , int )])
624
+ cls .b = np .array (zip (np .arange (10 ), np .arange (65 , 75 ),
625
+ np .arange (100 , 110 )),
626
+ dtype = [('a' , int ), ('b' , int ), ('d' , int )])
627
+
628
+ def test_no_r1postfix (self ):
629
+ "Basic test of join_by"
630
+ a , b = self .a , self .b
631
+
632
+ test = join_by ('a' , a , b , r1postfix = '' , r2postfix = '2' , jointype = 'inner' )
633
+ control = np .array ([(0 , 50 , 65 , 100 , 100 ), (1 , 51 , 66 , 101 , 101 ),
634
+ (2 , 52 , 67 , 102 , 102 ), (3 , 53 , 68 , 103 , 103 ),
635
+ (4 , 54 , 69 , 104 , 104 ), (5 , 55 , 70 , 105 , 105 ),
636
+ (6 , 56 , 71 , 106 , 106 ), (7 , 57 , 72 , 107 , 107 ),
637
+ (8 , 58 , 73 , 108 , 108 ), (9 , 59 , 74 , 109 , 109 )],
638
+ dtype = [('a' , int ), ('b' , int ), ('b2' , int ),
639
+ ('c' , int ), ('d' , int )])
640
+ assert_equal (test , control )
641
+
642
+
643
+ def test_no_postfix (self ):
644
+ self .assertRaises (ValueError , join_by , 'a' , self .a , self .b , r1postfix = '' , r2postfix = '' )
645
+
646
+ def test_no_r2postfix (self ):
647
+ "Basic test of join_by"
648
+ a , b = self .a , self .b
649
+
650
+ test = join_by ('a' , a , b , r1postfix = '1' , r2postfix = '' , jointype = 'inner' )
651
+ control = np .array ([(0 , 50 , 65 , 100 , 100 ), (1 , 51 , 66 , 101 , 101 ),
652
+ (2 , 52 , 67 , 102 , 102 ), (3 , 53 , 68 , 103 , 103 ),
653
+ (4 , 54 , 69 , 104 , 104 ), (5 , 55 , 70 , 105 , 105 ),
654
+ (6 , 56 , 71 , 106 , 106 ), (7 , 57 , 72 , 107 , 107 ),
655
+ (8 , 58 , 73 , 108 , 108 ), (9 , 59 , 74 , 109 , 109 )],
656
+ dtype = [('a' , int ), ('b1' , int ), ('b' , int ),
657
+ ('c' , int ), ('d' , int )])
658
+ assert_equal (test , control )
659
+
660
+ def test_two_keys_two_vars (self ):
661
+ a = np .array (zip (np .tile ([10 ,11 ],5 ),np .repeat (np .arange (5 ),2 ),
662
+ np .arange (50 , 60 ), np .arange (10 ,20 )),
663
+ dtype = [('k' , int ), ('a' , int ), ('b' , int ),('c' ,int )])
664
+
665
+ b = np .array (zip (np .tile ([10 ,11 ],5 ),np .repeat (np .arange (5 ),2 ),
666
+ np .arange (65 , 75 ), np .arange (0 ,10 )),
667
+ dtype = [('k' , int ), ('a' , int ), ('b' , int ), ('c' ,int )])
668
+
669
+ control = np .array ([(10 , 0 , 50 , 65 , 10 , 0 ), (11 , 0 , 51 , 66 , 11 , 1 ),
670
+ (10 , 1 , 52 , 67 , 12 , 2 ), (11 , 1 , 53 , 68 , 13 , 3 ),
671
+ (10 , 2 , 54 , 69 , 14 , 4 ), (11 , 2 , 55 , 70 , 15 , 5 ),
672
+ (10 , 3 , 56 , 71 , 16 , 6 ), (11 , 3 , 57 , 72 , 17 , 7 ),
673
+ (10 , 4 , 58 , 73 , 18 , 8 ), (11 , 4 , 59 , 74 , 19 , 9 )],
674
+ dtype = [('k' , '<i8' ), ('a' , '<i8' ), ('b1' , '<i8' ),
675
+ ('b2' , '<i8' ), ('c1' , '<i8' ), ('c2' , '<i8' )])
676
+ test = join_by (['a' ,'k' ], a , b , r1postfix = '1' , r2postfix = '2' , jointype = 'inner' )
677
+ assert_equal (test , control )
678
+
618
679
619
680
620
681
if __name__ == '__main__' :
0 commit comments