Skip to content

Commit 19e4124

Browse files
committed
RowInstance: use existing _x, _y, _metas for printout
RowInstance used to go back to the whole table when looking up values to convert to string. This is not needed.
1 parent 86d1fa7 commit 19e4124

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Orange/data/table.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,20 @@ def __setitem__(self, key, value):
160160
self._metas[-1 - key] = value
161161

162162
def _str(self, limit):
163-
def sp_values(matrix, variables):
164-
if not sp.issparse(matrix):
165-
if matrix.ndim == 1:
166-
matrix = matrix[:, np.newaxis]
167-
return Instance.str_values(matrix[row], variables, limit)
163+
def sp_values(row, variables, sparsity=None):
164+
if sparsity is None:
165+
return Instance.str_values(row, variables, limit)
168166

167+
# row is sparse
169168
row_entries, idx = [], 0
170169
while idx < len(variables):
171170
# Make sure to stop printing variables if we limit the output
172171
if limit and len(row_entries) >= 5:
173172
break
174173

175174
var = variables[idx]
176-
if var.is_discrete or matrix[row, idx]:
177-
row_entries.append("%s=%s" % (var.name, var.str_val(matrix[row, idx])))
175+
if var.is_discrete or row[idx]:
176+
row_entries.append("%s=%s" % (var.name, var.str_val(row[idx])))
178177

179178
idx += 1
180179

@@ -185,15 +184,13 @@ def sp_values(matrix, variables):
185184

186185
return s
187186

188-
table = self.table
189-
domain = table.domain
190-
row = self.row_index
191-
s = "[" + sp_values(table.X, domain.attributes)
187+
domain = self._domain
188+
s = "[" + sp_values(self._x, domain.attributes, self.sparse_x)
192189
if domain.class_vars:
193-
s += " | " + sp_values(table.Y, domain.class_vars)
190+
s += " | " + sp_values(self._y, domain.class_vars, self.sparse_y)
194191
s += "]"
195-
if self._domain.metas:
196-
s += " {" + sp_values(table.metas, domain.metas) + "}"
192+
if domain.metas:
193+
s += " {" + sp_values(self._metas, domain.metas, self.sparse_metas) + "}"
197194
return s
198195

199196
def __str__(self):

0 commit comments

Comments
 (0)