File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -803,8 +803,11 @@ 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 ])
807- if len (self ) > 5 :
806+ head = 5
807+ if self .is_sparse ():
808+ head = min (self .X .shape [0 ], head )
809+ s = "[" + ",\n " .join (repr (ex ) for ex in self [:head ])
810+ if len (self ) > head :
808811 s += ",\n ..."
809812 s += "\n ]"
810813 return s
Original file line number Diff line number Diff line change @@ -1213,6 +1213,11 @@ def test_is_sparse(self):
12131213 table .X = sp .csr_matrix (table .X )
12141214 self .assertTrue (table .is_sparse ())
12151215
1216+ def test_repr_sparse_with_one_row (self ):
1217+ table = data .Table ("iris" )[:1 ]
1218+ table .X = sp .csr_matrix (table .X )
1219+ repr (table ) # make sure repr does not crash
1220+
12161221
12171222def column_sizes (table ):
12181223 return (len (table .domain .attributes ),
You can’t perform that action at this time.
0 commit comments