@@ -1138,11 +1138,6 @@ class TableTests(unittest.TestCase):
11381138 nrows = 10
11391139 row_indices = (1 , 5 , 7 , 9 )
11401140
1141- data = np .random .random ((nrows , len (attributes )))
1142- class_data = np .random .random ((nrows , len (class_vars )))
1143- meta_data = np .random .random ((nrows , len (metas )))
1144- weight_data = np .random .random ((nrows , 1 ))
1145-
11461141 def setUp (self ):
11471142 self .data = np .random .random ((self .nrows , len (self .attributes )))
11481143 self .class_data = np .random .random ((self .nrows , len (self .class_vars )))
@@ -1584,11 +1579,13 @@ class CreateTableWithDomainAndTable(TableTests):
15841579 slice (None ), # [:] - all elements
15851580 slice (None , None , 2 ), # [::2] - even elements
15861581 slice (None , None , - 1 ), # [::-1]- all elements reversed
1582+ slice (9 , 5 , - 10 ), # slice a big negative stride and thus 1 element
15871583 ]
15881584
15891585 row_indices = [1 , 5 , 6 , 7 ]
15901586
15911587 def setUp (self ):
1588+ super ().setUp ()
15921589 self .domain = self .create_domain (
15931590 self .attributes , self .class_vars , self .metas )
15941591 self .table = data .Table (
@@ -1632,12 +1629,27 @@ def test_can_filter_rows_with_list(self):
16321629 self .assert_table_with_filter_matches (
16331630 new_table , self .table , rows = indices )
16341631
1635- def test_can_filter_row_with_slice (self ):
1632+ @patch .object (Table , "from_table_rows" , wraps = Table .from_table_rows )
1633+ def test_can_filter_row_with_slice_from_table_rows (self , from_table_rows ):
1634+ # calling from_table with the same domain will forward to from_table_rows
16361635 for slice_ in self .interesting_slices :
1636+ from_table_rows .reset_mock ()
16371637 new_table = data .Table .from_table (
16381638 self .domain , self .table , row_indices = slice_ )
16391639 self .assert_table_with_filter_matches (
16401640 new_table , self .table , rows = slice_ )
1641+ from_table_rows .assert_called ()
1642+
1643+ @patch .object (Table , "from_table_rows" , wraps = Table .from_table_rows )
1644+ def test_can_filter_row_with_slice_from_table (self , from_table_rows ):
1645+ # calling from_table with a domain copy will use indexing in from_table
1646+ for slice_ in self .interesting_slices :
1647+ from_table_rows .reset_mock ()
1648+ new_table = data .Table .from_table (
1649+ self .domain .copy (), self .table , row_indices = slice_ )
1650+ self .assert_table_with_filter_matches (
1651+ new_table , self .table , rows = slice_ )
1652+ from_table_rows .assert_not_called ()
16411653
16421654 def test_can_use_attributes_as_new_columns (self ):
16431655 a , _ , _ = column_sizes (self .table )
0 commit comments