File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,10 @@ def mapToSourceRows(self, rows):
127127 Source rows matching input rows. If they are the same,
128128 simply input `rows` is returned.
129129 """
130- if self .__sortInd is not None :
130+ # self.__sortInd[rows] fails if `rows` is an empty list or array
131+ if self .__sortInd is not None \
132+ and (isinstance (rows , (int , type (Ellipsis )))
133+ or len (rows )):
131134 new_rows = self .__sortInd [rows ]
132135 if rows is Ellipsis :
133136 new_rows .setflags (write = False )
Original file line number Diff line number Diff line change 33
44from unittest import TestCase
55
6+ import numpy as np
7+
68from AnyQt .QtCore import Qt
79
810from Orange .data import Domain , ContinuousVariable , DiscreteVariable
@@ -133,6 +135,24 @@ def test_sorting(self):
133135 self .model .sort (1 , Qt .DescendingOrder )
134136 self .assertSequenceEqual (self .model .mapToSourceRows (...).tolist (), [0 , 1 ])
135137
138+ def test_mapToSourceRows (self ):
139+ self .model .sort (1 , Qt .AscendingOrder )
140+ self .assertSequenceEqual (
141+ self .model .mapToSourceRows (...).tolist (),
142+ [1 , 0 ])
143+ self .assertEqual (
144+ self .model .mapToSourceRows (1 ).tolist (),
145+ 0 )
146+ self .assertSequenceEqual (
147+ self .model .mapToSourceRows ([1 , 0 ]).tolist (),
148+ [0 , 1 ])
149+ self .assertSequenceEqual (
150+ self .model .mapToSourceRows ([]),
151+ [])
152+ self .assertSequenceEqual (
153+ self .model .mapToSourceRows (np .array ([], dtype = int )).tolist (),
154+ [])
155+
136156
137157class TestPyListModel (TestCase ):
138158 @classmethod
You can’t perform that action at this time.
0 commit comments