Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
display constant value; add number of zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedockes committed Jan 15, 2024
1 parent b80db12 commit 544a3b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/skrubview/_data/templates/column-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ <h3 class="skrubview-margin-r-t">
<dl>
<dt>Null values</dt>
<dd class="skrubview-{{ column.nulls_level }}">{{ column.null_count }} ({{ column.null_proportion | format_percent }})</dd>
{% if not column.value_is_constant %}
{% if column.n_unique %}
<dt>Unique values</dt>
<dd>{{ column.n_unique }} ({{ column.unique_proportion | format_percent }})</dd>
{% endif %}

{% if column.value_is_constant %}
<dt>(constant) Value</dt>
<dd class=".skrubview-ellided">{{ column.constant_value.__repr__() }}</dd>
{% else %}
{% if column.n_zeros %}
<dt>Zeros</dt>
<dd>{{ column.n_zeros }} ({{ column.zeros_proportion | format_percent }})</dd>
{% endif %}
{% if "mean" in column %}
<dt>Mean ± Std</dt>
<dd>{{ column["mean"] | format_number }} ± {{ column["standard_deviation"] | format_number }}</dd>
Expand Down Expand Up @@ -48,6 +48,17 @@ <h3 class="skrubview-margin-r-t">
</dl>
</div>

{% if column.value_is_constant %}
{% set val_id = "{}-constant-value".format(col_id) %}
<div class="skrubview-margin-v-t">
<strong>Constant value:</strong>
<div class="skrubview-copybutton-grid">
<pre class="skrubview-box" id="{{ val_id }}">{{ column.constant_value }}</pre>
<button onclick='copyTextToClipboard("{{ val_id }}")'>📋</button>
</div>
</div>
{% endif %}

{% for plot_name in column.plot_names %}
<div>
<img class="pure-img" src="{{ column[plot_name] | svg_to_img_src | safe }}" alt={{ plot_name }} />
Expand Down
13 changes: 10 additions & 3 deletions src/skrubview/_summarize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path

import numpy as np
import polars as pl

from . import _plotting, _utils
Expand Down Expand Up @@ -65,7 +64,11 @@ def _summarize_column(
summary, column, dataframe_summary=dataframe_summary, with_plots=with_plots
)
_add_numeric_summary(
summary, column, with_plots=with_plots, order_by_column=order_by_column
summary,
column,
dataframe_summary=dataframe_summary,
with_plots=with_plots,
order_by_column=order_by_column,
)
_add_datetime_summary(summary, column, with_plots=with_plots)
summary["plot_names"] = [k for k in summary.keys() if k.endswith("_plot")]
Expand Down Expand Up @@ -131,12 +134,16 @@ def _add_datetime_summary(summary, column, with_plots):
)


def _add_numeric_summary(summary, column, with_plots, order_by_column):
def _add_numeric_summary(
summary, column, dataframe_summary, with_plots, order_by_column
):
ns = column.__column_namespace__()
if not ns.is_dtype(_utils.get_dtype(column), "numeric"):
return
if not summary["high_cardinality"]:
return
summary["n_zeros"] = int((column == 0).sum().scalar)
summary["zeros_proportion"] = summary["n_zeros"] / dataframe_summary["n_rows"]
std = column.std().scalar
summary["standard_deviation"] = float("nan") if std is None else float(std)
summary["mean"] = float(column.mean())
Expand Down
9 changes: 8 additions & 1 deletion src/skrubview/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ def _print_column_summary(summary, console):
text.append(f"[bold]{summary['dtype']}[/bold]\n")
text.append("Null values: ")
color = _COLORS[summary["nulls_level"]]
text.append(f"[{color}]{summary['null_proportion']:0.2%}[/{color}]\n")
text.append(
f"[{color}]{summary['null_count']} "
f"({summary['null_proportion']:0.2%})[/{color}]\n"
)
if "n_zeros" in summary:
text.append(
f"Zeros: {summary['n_zeros']} ({summary['zeros_proportion']:0.2%})\n"
)
if "n_unique" in summary:
text.append(f"Unique values: {summary['n_unique']}\n")
if "value_counts" in summary:
Expand Down

0 comments on commit 544a3b6

Please sign in to comment.