@@ -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