Skip to content

Commit 317aa53

Browse files
committed
Table.__repr__: Fix for sparse data with < 5 instances
Scipy does not support indexing table[:5] if table has less than 5 rows.
1 parent d9d3286 commit 317aa53

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Orange/data/table.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,10 @@ def __str__(self):
803803
return "[" + ",\n ".join(str(ex) for ex in self)
804804

805805
def __repr__(self):
806-
s = "[" + ",\n ".join(repr(ex) for ex in self[:5])
806+
head = 5
807+
if sp.issparse(self.X):
808+
head = min(self.X.shape[0], head)
809+
s = "[" + ",\n ".join(repr(ex) for ex in self[:head])
807810
if len(self) > 5:
808811
s += ",\n ..."
809812
s += "\n]"

0 commit comments

Comments
 (0)