44from AnyQt .QtWidgets import QApplication , QStyle , QSizePolicy
55
66import numpy as np
7+ import scipy .sparse as sp
78
89import Orange
910from Orange .data import StringVariable , ContinuousVariable
11+ from Orange .data .util import hstack
1012from Orange .widgets import widget , gui , settings
1113from Orange .widgets .utils import itemmodels
1214from Orange .widgets .utils .sql import check_sql_input
@@ -362,20 +364,29 @@ def _join_table_by_indices(self, reduced_extra, indices):
362364 def _join_array_by_indices (left , right , indices , string_cols = None ):
363365 """Join (horizontally) two arrays, taking pairs of rows given in indices
364366 """
365- tpe = object if object in (left .dtype , right .dtype ) else left .dtype
366- left_width , right_width = left .shape [1 ], right .shape [1 ]
367- arr = np .full ((indices .shape [1 ], left_width + right_width ), np .nan , tpe )
368- if string_cols :
369- arr [:, string_cols ] = ""
370- for indices , to_change , lookup in (
371- (indices [0 ], arr [:, :left_width ], left ),
372- (indices [1 ], arr [:, left_width :], right )):
373- known = indices != - 1
374- to_change [known ] = lookup [indices [known ]]
375- return arr
376-
377-
378- def test ():
367+ def prepare (arr , inds , str_cols ):
368+ try :
369+ newarr = arr [inds ]
370+ except IndexError :
371+ newarr = np .full_like (arr , np .nan )
372+ else :
373+ empty = np .full (arr .shape [1 ], np .nan )
374+ if str_cols :
375+ assert arr .dtype == object
376+ empty = empty .astype (object )
377+ empty [str_cols ] = ''
378+ newarr [inds == - 1 ] = empty
379+ return newarr
380+
381+ left_width = left .shape [1 ]
382+ str_left = [i for i in string_cols or () if i < left_width ]
383+ str_right = [i - left_width for i in string_cols or () if i >= left_width ]
384+ res = hstack ((prepare (left , indices [0 ], str_left ),
385+ prepare (right , indices [1 ], str_right )))
386+ return res
387+
388+
389+ def main ():
379390 app = QApplication ([])
380391 w = OWMergeData ()
381392 data = Orange .data .Table ("tests/data-gender-region" )
@@ -388,4 +399,4 @@ def test():
388399
389400
390401if __name__ == "__main__" :
391- test ()
402+ main ()
0 commit comments