This is an automated email from the ASF dual-hosted git repository.
jeffreyvo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 67af92e1be fix: display `0 secs` for empty DayTime/MonthDayNano
intervals (#9023)
67af92e1be is described below
commit 67af92e1bee758d81f8d582ac9d336c21a88d2f4
Author: Jeffrey Vo <[email protected]>
AuthorDate: Sat Jan 10 16:20:14 2026 +0900
fix: display `0 secs` for empty DayTime/MonthDayNano intervals (#9023)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- Closes #5914
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
See
https://github.com/apache/arrow-rs/issues/5914#issuecomment-3301251287
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
If DayTime/MonthDayNano intervals are empty, write `0 secs` for display.
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Updated existing tests.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
Minor change in display behaviour (previously wrote out an empty string)
Co-authored-by: Andrew Lamb <[email protected]>
---
arrow-cast/src/display.rs | 12 ++++++++++++
arrow-cast/src/pretty.rs | 4 ++++
2 files changed, 16 insertions(+)
diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs
index 202aff25cc..bfd0f06dbe 100644
--- a/arrow-cast/src/display.rs
+++ b/arrow-cast/src/display.rs
@@ -929,6 +929,12 @@ impl DisplayIndex for
&PrimitiveArray<IntervalYearMonthType> {
impl DisplayIndex for &PrimitiveArray<IntervalDayTimeType> {
fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult {
let value = self.value(idx);
+
+ if value.is_zero() {
+ write!(f, "0 secs")?;
+ return Ok(());
+ }
+
let mut prefix = "";
if value.days != 0 {
@@ -952,6 +958,12 @@ impl DisplayIndex for &PrimitiveArray<IntervalDayTimeType>
{
impl DisplayIndex for &PrimitiveArray<IntervalMonthDayNanoType> {
fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult {
let value = self.value(idx);
+
+ if value.is_zero() {
+ write!(f, "0 secs")?;
+ return Ok(());
+ }
+
let mut prefix = "";
if value.months != 0 {
diff --git a/arrow-cast/src/pretty.rs b/arrow-cast/src/pretty.rs
index fbf9e1613b..e7c199dbed 100644
--- a/arrow-cast/src/pretty.rs
+++ b/arrow-cast/src/pretty.rs
@@ -1108,6 +1108,7 @@ mod tests {
Some(IntervalDayTime::new(0, 1)),
Some(IntervalDayTime::new(0, 10)),
Some(IntervalDayTime::new(0, 100)),
+ Some(IntervalDayTime::new(0, 0)),
]));
let schema = Arc::new(Schema::new(vec![Field::new(
@@ -1130,6 +1131,7 @@ mod tests {
"| 0.001 secs |",
"| 0.010 secs |",
"| 0.100 secs |",
+ "| 0 secs |",
"+------------------+",
];
@@ -1154,6 +1156,7 @@ mod tests {
Some(IntervalMonthDayNano::new(0, 0, 10_000_000)),
Some(IntervalMonthDayNano::new(0, 0, 100_000_000)),
Some(IntervalMonthDayNano::new(0, 0, 1_000_000_000)),
+ Some(IntervalMonthDayNano::new(0, 0, 0)),
]));
let schema = Arc::new(Schema::new(vec![Field::new(
@@ -1183,6 +1186,7 @@ mod tests {
"| 0.010000000 secs |",
"| 0.100000000 secs |",
"| 1.000000000 secs |",
+ "| 0 secs |",
"+--------------------------+",
];