@@ -7,8 +7,6 @@ use std::fmt::Display;
77
88use itertools:: Itertools as _;
99use tree:: TreeDisplayWrapper ;
10- #[ cfg( feature = "table-display" ) ]
11- use vortex_error:: VortexExpect as _;
1210
1311use crate :: Array ;
1412
@@ -247,63 +245,62 @@ impl dyn Array + '_ {
247245 DisplayOptions :: TreeDisplay => write ! ( f, "{}" , TreeDisplayWrapper ( self . to_array( ) ) ) ,
248246 #[ cfg( feature = "table-display" ) ]
249247 DisplayOptions :: TableDisplay => {
248+ use vortex_dtype:: DType ;
249+ use vortex_error:: VortexExpect as _;
250+
250251 use crate :: canonical:: ToCanonical ;
252+
251253 let mut builder = tabled:: builder:: Builder :: default ( ) ;
252254
253- let table = match self . dtype ( ) {
254- vortex_dtype:: DType :: Struct ( sf, _) => {
255- let struct_ = self . to_struct ( ) . vortex_expect ( "struct array" ) ;
256- builder. push_record ( sf. names ( ) . iter ( ) . map ( |name| name. to_string ( ) ) ) ;
257-
258- for row_idx in 0 ..self . len ( ) {
259- if !self . is_valid ( row_idx) . vortex_expect ( "index in bounds" ) {
260- let null_row = vec ! [ "null" . to_string( ) ; sf. names( ) . len( ) ] ;
261- builder. push_record ( null_row) ;
262- } else {
263- let mut row = Vec :: new ( ) ;
264- for field_array in struct_. fields ( ) {
265- let value = field_array. scalar_at ( row_idx) ;
266- row. push ( value. to_string ( ) ) ;
267- }
268- builder. push_record ( row) ;
269- }
270- }
255+ // Special logic for struct arrays.
256+ let DType :: Struct ( sf, _) = self . dtype ( ) else {
257+ // For non-struct arrays, simply display a single column table without header.
258+ for row_idx in 0 ..self . len ( ) {
259+ let value = self . scalar_at ( row_idx) ;
260+ builder. push_record ( [ value. to_string ( ) ] ) ;
261+ }
271262
272- let mut table = builder. build ( ) ;
273- table. with ( tabled:: settings:: Style :: modern ( ) ) ;
263+ let mut table = builder. build ( ) ;
264+ table. with ( tabled:: settings:: Style :: modern ( ) ) ;
274265
275- // Center headers
276- for col_idx in 0 ..sf. names ( ) . len ( ) {
277- table. modify ( ( 0 , col_idx) , tabled:: settings:: Alignment :: center ( ) ) ;
278- }
266+ return write ! ( f, "{table}" ) ;
267+ } ;
279268
280- for row_idx in 0 ..self . len ( ) {
281- if !self . is_valid ( row_idx) . vortex_expect ( "index is in bounds" ) {
282- table. modify (
283- ( 1 + row_idx, 0 ) ,
284- tabled:: settings:: Span :: column ( sf. names ( ) . len ( ) as isize ) ,
285- ) ;
286- table. modify (
287- ( 1 + row_idx, 0 ) ,
288- tabled:: settings:: Alignment :: center ( ) ,
289- ) ;
290- }
269+ let struct_ = self . to_struct ( ) . vortex_expect ( "struct array" ) ;
270+ builder. push_record ( sf. names ( ) . iter ( ) . map ( |name| name. to_string ( ) ) ) ;
271+
272+ for row_idx in 0 ..self . len ( ) {
273+ if !self . is_valid ( row_idx) . vortex_expect ( "index in bounds" ) {
274+ let null_row = vec ! [ "null" . to_string( ) ; sf. names( ) . len( ) ] ;
275+ builder. push_record ( null_row) ;
276+ } else {
277+ let mut row = Vec :: new ( ) ;
278+ for field_array in struct_. fields ( ) {
279+ let value = field_array. scalar_at ( row_idx) ;
280+ row. push ( value. to_string ( ) ) ;
291281 }
292- table
282+ builder . push_record ( row ) ;
293283 }
294- _ => {
295- // For non-struct arrays, display a single column table without header
296- for row_idx in 0 ..self . len ( ) {
297- let value = self . scalar_at ( row_idx) ;
298- builder. push_record ( [ value. to_string ( ) ] ) ;
299- }
300-
301- let mut table = builder. build ( ) ;
302- table. with ( tabled:: settings:: Style :: modern ( ) ) ;
303-
304- table
284+ }
285+
286+ let mut table = builder. build ( ) ;
287+ table. with ( tabled:: settings:: Style :: modern ( ) ) ;
288+
289+ // Center headers
290+ for col_idx in 0 ..sf. names ( ) . len ( ) {
291+ table. modify ( ( 0 , col_idx) , tabled:: settings:: Alignment :: center ( ) ) ;
292+ }
293+
294+ for row_idx in 0 ..self . len ( ) {
295+ if !self . is_valid ( row_idx) . vortex_expect ( "index is in bounds" ) {
296+ table. modify (
297+ ( 1 + row_idx, 0 ) ,
298+ tabled:: settings:: Span :: column ( sf. names ( ) . len ( ) as isize ) ,
299+ ) ;
300+ table. modify ( ( 1 + row_idx, 0 ) , tabled:: settings:: Alignment :: center ( ) ) ;
305301 }
306- } ;
302+ }
303+
307304 write ! ( f, "{table}" )
308305 }
309306 }
0 commit comments