pl2html 0.4.0__tar.gz → 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pl2html-0.4.0 → pl2html-0.4.1}/PKG-INFO +1 -1
- {pl2html-0.4.0 → pl2html-0.4.1}/pl2html/__init__.py +1 -1
- {pl2html-0.4.0 → pl2html-0.4.1}/pl2html/formats.py +9 -9
- {pl2html-0.4.0 → pl2html-0.4.1}/pyproject.toml +1 -1
- {pl2html-0.4.0 → pl2html-0.4.1}/README.md +0 -0
- {pl2html-0.4.0 → pl2html-0.4.1}/pl2html/styles.py +0 -0
|
@@ -48,6 +48,7 @@ def fmt_number(
|
|
|
48
48
|
Highly optimized, native Polars numeric formatter matching great_tables features.
|
|
49
49
|
Runs entirely in the parallel Rust engine without dropping into Python row loops.
|
|
50
50
|
"""
|
|
51
|
+
col_name = columns if isinstance(columns, str) else str(columns)
|
|
51
52
|
val = _col(columns)
|
|
52
53
|
if scale_by != 1.0:
|
|
53
54
|
val = val * scale_by
|
|
@@ -61,6 +62,13 @@ def fmt_number(
|
|
|
61
62
|
)
|
|
62
63
|
thousands_exponent = (log10_expr / 3.0).floor().cast(_Int32) * 3
|
|
63
64
|
|
|
65
|
+
# Force exponent to 0 for fractional numbers (< 1.0) so we don't scale up without micro-suffixes
|
|
66
|
+
thousands_exponent = (
|
|
67
|
+
_when(thousands_exponent < 0)
|
|
68
|
+
.then(_lit(0))
|
|
69
|
+
.otherwise(thousands_exponent)
|
|
70
|
+
)
|
|
71
|
+
|
|
64
72
|
if compact_system == 'engineering':
|
|
65
73
|
suffix_chain = (
|
|
66
74
|
_when(thousands_exponent == 3)
|
|
@@ -96,28 +104,23 @@ def fmt_number(
|
|
|
96
104
|
if n_sigfig < 1:
|
|
97
105
|
raise ValueError('n_sigfig must be a positive integer >= 1')
|
|
98
106
|
|
|
99
|
-
# Round natively using Polars' built-in significant figures feature
|
|
100
107
|
rounded = val_scaled.round_sig_figs(n_sigfig)
|
|
101
108
|
abs_rounded = rounded.abs()
|
|
102
109
|
|
|
103
|
-
# Determine the number of dynamic decimal places needed for padding per row
|
|
104
110
|
log10_expr = (
|
|
105
111
|
_when(abs_rounded > 0)
|
|
106
112
|
.then(abs_rounded.log10())
|
|
107
113
|
.otherwise(_lit(0.0))
|
|
108
114
|
)
|
|
109
|
-
# decimals required = n_sigfig - 1 - floor(log10(x))
|
|
110
115
|
dynamic_decimals = (_lit(n_sigfig - 1) - log10_expr.floor()).cast(
|
|
111
116
|
_Int32
|
|
112
117
|
)
|
|
113
|
-
# Ensure we don't try to pad negative decimal places for large numbers
|
|
114
118
|
dynamic_decimals = (
|
|
115
119
|
_when(dynamic_decimals < 0)
|
|
116
120
|
.then(_lit(0))
|
|
117
121
|
.otherwise(dynamic_decimals)
|
|
118
122
|
)
|
|
119
123
|
else:
|
|
120
|
-
# Fallback to standard fixed decimal logic
|
|
121
124
|
epsilon = (
|
|
122
125
|
_when(val_scaled >= 0).then(_lit(1e-9)).otherwise(_lit(-1e-9))
|
|
123
126
|
)
|
|
@@ -134,7 +137,6 @@ def fmt_number(
|
|
|
134
137
|
.otherwise(_lit(''))
|
|
135
138
|
)
|
|
136
139
|
|
|
137
|
-
# Use native Python string multiplication inside _lit()
|
|
138
140
|
pad_len = n_sigfig if n_sigfig is not None else decimals
|
|
139
141
|
frac_part = (
|
|
140
142
|
_when(dynamic_decimals > 0)
|
|
@@ -175,7 +177,6 @@ def fmt_number(
|
|
|
175
177
|
+ _lit(')')
|
|
176
178
|
)
|
|
177
179
|
.otherwise(
|
|
178
|
-
# If force_sign is True, explicitly prepend '+' to positive values
|
|
179
180
|
_lit('+' if force_sign else '')
|
|
180
181
|
+ _lit(prefix)
|
|
181
182
|
+ base_num_str
|
|
@@ -186,13 +187,12 @@ def fmt_number(
|
|
|
186
187
|
formatted_expr = (
|
|
187
188
|
_when(val < 0)
|
|
188
189
|
.then(_lit('-') + _lit(prefix) + base_num_str + _lit(suffix))
|
|
189
|
-
# Handle zero explicitly if you don't want a sign on exactly 0.0
|
|
190
190
|
.when((val == 0) | (not force_sign))
|
|
191
191
|
.then(_lit(prefix) + base_num_str + _lit(suffix))
|
|
192
192
|
.otherwise(_lit('+') + _lit(prefix) + base_num_str + _lit(suffix))
|
|
193
193
|
)
|
|
194
194
|
|
|
195
|
-
return formatted_expr
|
|
195
|
+
return formatted_expr.alias(col_name)
|
|
196
196
|
|
|
197
197
|
|
|
198
198
|
@_multicolumn
|
|
File without changes
|
|
File without changes
|