edponce commented on a change in pull request #12148:
URL: https://github.com/apache/arrow/pull/12148#discussion_r784329846



##########
File path: python/pyarrow/table.pxi
##########
@@ -1342,10 +1344,11 @@ cdef class Table(_PandasConvertible):
         if preview_cols:
             pieces.append('----')
             for i in range(min(self.num_columns, preview_cols)):
-                pieces.append('{}: {}'.format(
-                    self.field(i).name,
-                    self.column(i).to_string(indent=0, skip_new_lines=True)
-                ))
+                col_string = self.column(i).to_string(
+                    indent=0, skip_new_lines=True)
+                if len(col_string) > cols_char_limit:
+                    col_string = col_string[:(cols_char_limit - 3)] + '...'
+                pieces.append('{}: {}'.format(self.field(i).name, col_string))

Review comment:
       Ideally, we could always truncate "correctly" and consistently, that is, 
truncate at a delimiter and show closing brackets: `[[1,2,3,4,...]]`
   
   But several questions first:
   * Is the delimiter always a comma or known in a variable?
   * Is the table representation always encoded as a list of lists? Or can 
there be a less/more nesting?
   
   Assuming "yes" for the questions above. There are several cases that can 
occur:
   1. No truncation: `[[1,2,3,4]]`
   2. Truncate does not reaches the final end bracket (# of brackets is 
arbitrary): `[[1,2,3,4]...`
   3. Truncate mid-value: `[10,20,30,4...`
   3. Truncate at a value delimiter: `[[1,2,3,...`
   4. Truncate at a list delimiter: `[[1,2,3,4],...`
   5. Truncate at a list ending bracket: `[[1,2,3,4]...`
   
   To display all truncated cases "correctly" and consistently, after slicing 
the `cols_char_limit`, you would need
   * a stack to keep track of open/close bracket pairs
   * check which symbol is truncation occurring on.
   
   Then resolve as follows:
   * If it is a delimiter, then add `...` and match with closing brackets
   * If it is a closing bracket
      * and there are only closing bracket left, then add them to obtain the 
full representation.
      * add `...` and match with closing brackets
   * Else it is truncating a value, so remove (or add) characters until 
reaching a delimiter/bracket




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to