Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
uv.lock

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -85,3 +86,6 @@ docsrc/source/pages/api/_autosummary/
# User created
VERSION
version.py

# local java/spark sdk environment files
.sdkmanrc
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dev = [
"sphinx-autodoc-typehints>=1.10.3",
"sphinx-multiversion>=0.2.3",
"autodoc_pydantic",
"standard-imghdr"
]

docs = [
Expand Down
17 changes: 10 additions & 7 deletions src/ydata_profiling/report/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,16 @@ def fmt_numeric(value: float, precision: int = 10) -> str:
Returns:
The numeric value with the given precision.
"""
fmtted = f"{{:.{precision}g}}".format(value)
for v in ["e+", "e-"]:
if v in fmtted:
sign = "-" if v in "e-" else ""
fmtted = fmtted.replace(v, " × 10<sup>") + "</sup>"
fmtted = fmtted.replace("<sup>0", "<sup>")
fmtted = fmtted.replace("<sup>", f"<sup>{sign}")
if value is None:
fmtted = "N/A"
else:
fmtted = f"{{:.{precision}g}}".format(value)
for v in ["e+", "e-"]:
if v in fmtted:
sign = "-" if v in "e-" else ""
fmtted = fmtted.replace(v, " × 10<sup>") + "</sup>"
fmtted = fmtted.replace("<sup>0", "<sup>")
fmtted = fmtted.replace("<sup>", f"<sup>{sign}")

return fmtted

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_fmt_array(array, threshold, expected):
(1e20, 10, "1 × 10<sup>20</sup>"),
(1e-20, 10, "1 × 10<sup>-20</sup>"),
(1e8, 3, "1 × 10<sup>8</sup>"),
(None, 3, "N/A"),
],
)
def test_fmt_numeric(value, precision, expected):
Expand Down