Skip to content

Commit b1ab304

Browse files
Show truncation indicator in array display (#7072)
When displaying array values that exceed the display limit (16), we now show `...` between first 13 and last 3 elements. Makes it obvious the output is incomplete. --------- Signed-off-by: Dimitar Dimitrov <dimitar@spiraldb.com> Signed-off-by: Robert Kruszewski <github@robertk.io> Co-authored-by: Robert Kruszewski <github@robertk.io>
1 parent 236d5cc commit b1ab304

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

  • vortex-array/src/display

vortex-array/src/display/mod.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,30 @@ 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| {
489+
self.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(
498+
"...".to_string(),
499+
is_truncated as usize
500+
))
501+
.chain((self.len().saturating_sub(3)..self.len()).map(fmt_scalar))
491502
.format(sep)
492-
)?;
493-
write!(f, "{}", if f.alternate() { "\n]" } else { "]" })
503+
)
494504
}
495505
DisplayOptions::TreeDisplay {
496506
buffers,
@@ -583,6 +593,7 @@ mod test {
583593
use crate::arrays::BoolArray;
584594
use crate::arrays::ListArray;
585595
use crate::arrays::StructArray;
596+
use crate::display::DISPLAY_LIMIT;
586597
use crate::dtype::FieldNames;
587598
use crate::validity::Validity;
588599

@@ -596,6 +607,15 @@ mod test {
596607

597608
let x = buffer![1, 2, 3, 4].into_array();
598609
assert_eq!(x.display_values().to_string(), "[1i32, 2i32, 3i32, 4i32]");
610+
611+
let x = crate::arrays::PrimitiveArray::from_iter(
612+
0i32..i32::try_from(DISPLAY_LIMIT).unwrap() + 1,
613+
)
614+
.into_array();
615+
assert_eq!(
616+
x.display_values().to_string(),
617+
"[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, ..., 14i32, 15i32, 16i32]"
618+
);
599619
}
600620

601621
#[test]

0 commit comments

Comments
 (0)