@@ -477,20 +477,27 @@ impl dyn DynArray + '_ {
477477 DisplayOptions :: CommaSeparatedScalars {
478478 omit_comma_after_space,
479479 } => {
480- write ! ( f, "{}" , if f. alternate( ) { "[\n " } else { "[" } ) ?;
480+ let opening_brace= if f. alternate ( ) { "[\n " } else { "[" } ;
481+ let closing_brace = if f. alternate ( ) { "\n ]" } else { "]" } ;
482+
481483 let sep = if * omit_comma_after_space { "," } else { ", " } ;
482484 let sep = if f. alternate ( ) { ",\n " } else { sep } ;
483- let limit = std:: cmp:: min ( self . len ( ) , f. precision ( ) . unwrap_or ( DISPLAY_LIMIT ) ) ;
485+ let limit = self . len ( ) . min ( f. precision ( ) . unwrap_or ( DISPLAY_LIMIT ) ) ;
486+ let is_truncated = self . len ( ) > limit;
487+
488+ let fmt_scalar = |i| self
489+ . scalar_at ( i)
490+ . map_or_else ( |e| format ! ( "<error: {e}>" ) , |s| s. to_string ( ) ) ;
491+
484492 write ! (
485493 f,
486- "{}" ,
487- ( 0 ..limit)
488- . map( |i| self
489- . scalar_at ( i )
490- . map_or_else ( |e| format! ( "<error: {e}>" ) , |s| s . to_string ( ) ) )
494+ "{opening_brace}{}{closing_brace }" ,
495+ ( 0 ..limit. saturating_sub ( 3 ) )
496+ . map( fmt_scalar )
497+ . chain ( std :: iter :: repeat_n ( "..." . to_string ( ) , is_truncated as usize ) )
498+ . chain ( ( self . len ( ) . saturating_sub ( 3 ) .. self . len ( ) ) . map ( fmt_scalar ) )
491499 . format( sep)
492- ) ?;
493- write ! ( f, "{}" , if f. alternate( ) { "\n ]" } else { "]" } )
500+ )
494501 }
495502 DisplayOptions :: TreeDisplay {
496503 buffers,
@@ -583,6 +590,7 @@ mod test {
583590 use crate :: arrays:: BoolArray ;
584591 use crate :: arrays:: ListArray ;
585592 use crate :: arrays:: StructArray ;
593+ use crate :: display:: DISPLAY_LIMIT ;
586594 use crate :: dtype:: FieldNames ;
587595 use crate :: validity:: Validity ;
588596
@@ -596,6 +604,15 @@ mod test {
596604
597605 let x = buffer ! [ 1 , 2 , 3 , 4 ] . into_array ( ) ;
598606 assert_eq ! ( x. display_values( ) . to_string( ) , "[1i32, 2i32, 3i32, 4i32]" ) ;
607+
608+ let x = crate :: arrays:: PrimitiveArray :: from_iter (
609+ 0i32 ..i32:: try_from ( DISPLAY_LIMIT ) . unwrap ( ) + 1 ,
610+ )
611+ . into_array ( ) ;
612+ assert_eq ! (
613+ x. display_values( ) . to_string( ) ,
614+ "[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, ..., 14i32, 15i32, 16i32]"
615+ ) ;
599616 }
600617
601618 #[ test]
0 commit comments