Skip to content

Commit 5f3c8fb

Browse files
committed
Add the _format_single_float_with_gt() util fn
1 parent 8497291 commit 5f3c8fb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pointblank/validate.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13883,6 +13883,32 @@ def _format_number_safe(value: int) -> str:
1388313883

1388413884
def _fmt_lg(value: int, locale: str) -> str:
1388513885
return vals.fmt_number(value, n_sigfig=3, compact=True, locale=locale)[0]
13886+
def _format_single_float_with_gt(
13887+
value: float, decimals: int = 2, locale: str = "en", df_lib=None
13888+
) -> str:
13889+
if df_lib is None:
13890+
# Use library detection to select appropriate DataFrame library
13891+
if _is_lib_present("polars"):
13892+
import polars as pl
13893+
13894+
df_lib = pl
13895+
elif _is_lib_present("pandas"):
13896+
import pandas as pd
13897+
13898+
df_lib = pd
13899+
else:
13900+
raise ImportError("Neither Polars nor Pandas is available for formatting")
13901+
13902+
# Create a single-row, single-column DataFrame using the specified library
13903+
df = df_lib.DataFrame({"value": [value]})
13904+
13905+
# Create GT object and format the column
13906+
gt_obj = GT(df).fmt_number(columns="value", decimals=decimals, locale=locale)
13907+
13908+
# Extract the formatted value using _get_column_of_values
13909+
formatted_values = _get_column_of_values(gt_obj, column_name="value", context="html")
13910+
13911+
return formatted_values[0] # Return the single formatted value
1388613912

1388713913

1388813914
def _transform_passed_failed(

0 commit comments

Comments
 (0)