@@ -65,7 +65,12 @@ def test_getitem_array_one_column(fancy_test_array: FancyTestArray):
6565
6666def test_getitem_array_multiple_columns (fancy_test_array : FancyTestArray ):
6767 columns = ["id" , "test_int" , "test_float" ]
68- assert_array_equal (fancy_test_array .data [columns ].dtype .names , ("id" , "test_int" , "test_float" ))
68+ assert_array_equal (fancy_test_array [columns ].dtype .names , ("id" , "test_int" , "test_float" ))
69+
70+
71+ def test_getitem_unique_multiple_columns (fancy_test_array : FancyTestArray ):
72+ columns = ["id" , "test_int" , "test_float" ]
73+ assert np .array_equal (np .unique (fancy_test_array [columns ]), fancy_test_array [columns ])
6974
7075
7176def test_getitem_array_index (fancy_test_array : FancyTestArray ):
@@ -80,7 +85,7 @@ def test_getitem_array_nested_index(fancy_test_array: FancyTestArray):
8085
8186
8287def test_getitem_array_slice (fancy_test_array : FancyTestArray ):
83- assert fancy_test_array [0 :2 ].data . tolist () == fancy_test_array . data [0 :2 ].tolist ()
88+ assert fancy_test_array . data [0 :2 ].tolist () == fancy_test_array [0 :2 ].tolist ()
8489
8590
8691def test_getitem_with_array_mask (fancy_test_array : FancyTestArray ):
@@ -89,21 +94,23 @@ def test_getitem_with_array_mask(fancy_test_array: FancyTestArray):
8994 assert np .array_equal (fancy_test_array .data [mask ], fancy_test_array [mask ].data )
9095
9196
92- def test_getitem_with_tuple_mask (fancy_test_array : FancyTestArray ):
93- mask = (True , False , True )
94- with pytest .raises (NotImplementedError ):
95- fancy_test_array [mask ] # type: ignore[call-overload] # noqa
96-
97-
9897def test_getitem_with_list_mask (fancy_test_array : FancyTestArray ):
9998 mask = [True , False , True ]
99+ assert isinstance (fancy_test_array [mask ], FancyArray )
100+ assert np .array_equal (fancy_test_array .data [mask ], fancy_test_array [mask ].data )
101+
102+
103+ def test_getitem_with_tuple_mask (fancy_test_array : FancyTestArray ):
104+ # Numpy gives unexpected results with tuple masks. Therefore, we raise NotImplementedError here.
105+ # e.g: np.array([1,2,3])[(True, False, True)] returns an empty array (array([], shape=(0, 3), dtype=int64)
106+ mask = (True , False , True )
100107 with pytest .raises (NotImplementedError ):
101108 fancy_test_array [mask ] # type: ignore[call-overload] # noqa
102109
103110
104111def test_getitem_with_empty_list_mask ():
105112 array = FancyTestArray ()
106- mask = np . array ([], dtype = bool )
113+ mask = []
107114 assert isinstance (array [mask ], FancyArray )
108115 assert np .array_equal (array .data [mask ], array [mask ].data )
109116
@@ -238,16 +245,16 @@ def test_unique_return_counts_and_inverse(fancy_test_array: FancyTestArray):
238245
239246
240247def test_sort (fancy_test_array : FancyTestArray ):
241- assert_array_equal (fancy_test_array [ " test_float" ] , [4.0 , 4.0 , 1.0 ])
242- fancy_test_array .data . sort (order = "test_float" )
243- assert_array_equal (fancy_test_array [ " test_float" ] , [1.0 , 4.0 , 4.0 ])
248+ assert_array_equal (fancy_test_array . test_float , [4.0 , 4.0 , 1.0 ])
249+ fancy_test_array .sort (order = "test_float" )
250+ assert_array_equal (fancy_test_array . test_float , [1.0 , 4.0 , 4.0 ])
244251
245252
246253def test_copy_function (fancy_test_array : FancyTestArray ):
247254 array_copy = copy (fancy_test_array )
248- array_copy [ " test_int" ] = 123
255+ array_copy . test_int = 123
249256 assert not id (fancy_test_array ) == id (array_copy )
250- assert not fancy_test_array [ " test_int" ] [0 ] == array_copy [ " test_int" ] [0 ]
257+ assert not fancy_test_array . test_int [0 ] == array_copy . test_int [0 ]
251258
252259
253260def test_copy_method (fancy_test_array : FancyTestArray ):
@@ -307,4 +314,4 @@ def test_from_extended_array():
307314
308315 array = LineArray .from_extended (extended_array )
309316 assert not isinstance (array , ExtendedLineArray )
310- array_equal_with_nan (array .data , extended_array . data [array .columns ])
317+ array_equal_with_nan (array .data , extended_array [array .columns ])
0 commit comments