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 @@ -802,8 +802,11 @@ def __str__(self):
802802 return "[" + ",\n " .join (str (ex ) for ex in self )
803803
804804 def __repr__ (self ):
805- s = "[" + ",\n " .join (repr (ex ) for ex in self [:5 ])
806- if len (self ) > 5 :
805+ head = 5
806+ if self .is_sparse ():
807+ head = min (self .X .shape [0 ], head )
808+ s = "[" + ",\n " .join (repr (ex ) for ex in self [:head ])
809+ if len (self ) > head :
807810 s += ",\n ..."
808811 s += "\n ]"
809812 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