@@ -43,3 +43,44 @@ def test_join_arrays_join_types(join_type, expected_data, expected_row):
43
43
join_type = join_type )
44
44
assert np .allclose (np .array ([[x [0 ], x [1 ]] for x in data ]), expected_data )
45
45
assert np .allclose (row , expected_row )
46
+
47
+
48
+ @pytest .mark .parametrize ("join_type, expected_data, expected_row" , [
49
+ ["left" , np .array ([[0 , 0 ], [1 , 0 ], [2 , 2 ], [4 , 0 ], [5 , 5 ]]), np .array ([0 , 1 , 2 , 4 , 5 ])],
50
+ ["right" , np .array ([[2 , 2 ],[0 , 3 ], [5 , 5 ], [0 , 6 ], [0 , 7 ],]), np .array ([2 , 3 , 5 , 6 , 7 ])],
51
+ ["inner" , np .array ([[2 , 2 ], [5 , 5 ]]), np .array ([2 , 5 ])],
52
+ ["outer" , np .array ([[0 , 0 ], [1 , 0 ], [2 , 2 ], [0 , 3 ], [4 , 0 ], [5 , 5 ], [0 , 6 ], [0 , 7 ]]),
53
+ np .array ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ])],
54
+ ])
55
+ def test_join_arrays_join_types (join_type , expected_data , expected_row ):
56
+ row1 = np .array ([0 , 1 , 2 , 4 , 5 ])
57
+ col1 = np .array ([0 , 1 , 2 , 4 , 5 ])
58
+ row2 = np .array ([7 , 5 , 3 , 6 , 2 ])
59
+ col2 = np .array ([7 , 5 , 3 , 6 , 2 ])
60
+ data1 = np .array (col1 , dtype = [("layer1" , col1 .dtype )])
61
+ data2 = np .array (col2 , dtype = [("layer2" , col2 .dtype )])
62
+
63
+ row , col , data = join_arrays (row1 , col1 , data1 , row2 , col2 , data2 , "test1" ,
64
+ join_type = join_type )
65
+ assert np .allclose (np .array ([[x [0 ], x [1 ]] for x in data ]), expected_data )
66
+ assert np .allclose (row , expected_row )
67
+
68
+
69
+ @pytest .mark .parametrize ("join_type" , [
70
+ "left" , "right" , "inner" , "outer"
71
+ ])
72
+ def test_join_arrays_larger (join_type ):
73
+ """Joining two identical arrays should always give the same result."""
74
+ row = np .array ([ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 6 , 15 , 7 , 7 , 8 , 7 , 9 , 7 , 10 , 7 ,
75
+ 11 , 8 , 8 , 9 , 8 , 10 , 8 , 11 , 9 , 9 , 10 , 9 , 11 , 10 , 10 , 11 , 11 ,
76
+ 12 , 12 , 13 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ])
77
+
78
+ col = np .array ([ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 15 , 6 , 7 , 8 , 7 , 9 , 7 , 10 , 7 , 11 ,
79
+ 7 , 8 , 9 , 8 , 10 , 8 , 11 , 8 , 9 , 10 , 9 , 11 , 9 , 10 , 11 , 10 , 11 ,
80
+ 12 , 13 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ])
81
+ data1 = np .array (np .arange (0 , len (col )), dtype = [("layer1" , col .dtype )])
82
+ data2 = np .array (np .arange (0 , len (col )), dtype = [("layer2" , col .dtype )])
83
+
84
+ row_out , col_out , data_out = join_arrays (row , col , data1 , row , col , data2 , "test1" ,
85
+ join_type = join_type )
86
+ assert np .allclose (sorted (data_out ["test1_layer2" ]), sorted (np .array ([x [0 ] for x in data2 ])))
0 commit comments