-
Notifications
You must be signed in to change notification settings - Fork 60
Apply Polars float_precision config to Array[f64] and List[f64] columns using native Polars formatting #472
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mwouts <[email protected]>
…check Co-authored-by: mwouts <[email protected]>
mwouts
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I would prefer to use a Polars method to apply the formatting, can you do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change that file? The change does not relate to the current PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted in c1b63d6. These files were accidentally modified during the initial commit and are now restored to their original state.
src/itables/datatables_format.py
Outdated
| values = x.round(precision).to_list() | ||
| return [escape_non_finite_float(v) for v in values] | ||
|
|
||
| # Array and List types with float inner dtype - apply formatting to nested values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to know where in the Polars codebase this logic is applied. I would prefer to re-use the Polars implementation rather than to re-code it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored in c1b63d6 to use Polars' native _s.get_fmt() method. This method is called internally by Series.__str__() and respects all Polars config settings including float_precision and fmt_table_cell_list_len. The implementation is now much simpler (~10 lines vs ~50) and guarantees perfect alignment with Polars' display formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect changes here either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted in c1b63d6. These changes were unintentional and have been removed.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #472 +/- ##
==========================================
+ Coverage 93.84% 93.99% +0.14%
==========================================
Files 46 46
Lines 2373 2446 +73
==========================================
+ Hits 2227 2299 +72
- Misses 146 147 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: mwouts <[email protected]>
|
Thank you for making this pull request. Did you know? You can try it on Binder: Also, the version of ITables developed in this PR is available as a wheel artifact 📦 for easy installation. A conda package is also available for easy installation: |
Polars
float_precisionconfig was ignored for nested float types (Array[Float64], List[Float64]), causing inconsistent display between regular and nested columns.Changes
Modified
_format_polars_seriesindatatables_format.py:dtype.is_nested()anddtype.inner_s.get_fmt()method which is the same method Polars uses internally for string representationescape_special_floats_in_string()helper to handle NaN/Inf encoding in formatted stringsfmt_table_cell_list_len=1000to avoid truncation in array/list outputAdded test coverage:
Example
Benefits
float_precision,fmt_table_cell_list_len, etc.)Original prompt
array[f64]orlist[f64]#471💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.