Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format integer floats without .0 suffix #6951

Closed
wants to merge 1 commit into from

Conversation

emilk
Copy link
Contributor

@emilk emilk commented Jan 7, 2025

Rationale for this change

When formatting 32-bit or 64-bit floats, the current formatter always includes a .0 suffix on integers, so that zero is formatted as 0.0, one as 1.0, etc. In cases where there is a lot of zeros (or integers), that can result in a lot of visual noise in the output.

By contrast, the standard float formatter in Rust formats integers without a .0 suffix.
Similarly, the float formatter for f16 in arrow also does not include the .0 suffix, meaning the float formatting in arrow is inconsistent with both std and itself.

Changes

This removes any .0 suffix on formatted floats, so that zero is always formatted as 0, regardless if it is stored as f16, f32 or u32.

Alternatives

We could add this as an option to FormatOptions, but that would require a larger refactor in order to access FormatOptions in impl DisplayIndex for PrimitiveArray<Float32Type>

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 7, 2025
@tustvold
Copy link
Contributor

tustvold commented Jan 7, 2025

IIRC this is intentional to allow schema inference to work reliably, this probably does need to be an opt-in change

@alamb
Copy link
Contributor

alamb commented Jan 7, 2025

IIRC this is intentional to allow schema inference to work reliably, this probably does need to be an opt-in change

Specifically, it could be an option on CastOptions passed via

https://docs.rs/arrow/latest/arrow/compute/kernels/cast/fn.cast_with_options.html

emilk added a commit to rerun-io/rerun that referenced this pull request Jan 7, 2025
### Related
* Follow-up to #8590
* Part of #3741
* ~Blocked on apache/arrow-rs#6951

### What
Uses `arrow-rs` own formatting of arrow values.

Unfortunately this adds a `.0` suffix to all integer floating point
values, which makes them quite verbose. I will see if there is a way
around that.
@emilk
Copy link
Contributor Author

emilk commented Jan 8, 2025

We decided that the extra .0 in our output is fine for now - maybe I'll revisit this in the future. Thanks for the feedback!

@emilk emilk closed this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants