summary_algorithms
¶
Statistics helpers shared by the summary steps.
Everything here works on small, already-aggregated inputs (value counts, bin counts, distinct characters) produced by lazy Polars queries; nothing touches the full column.
Classes¶
ValueCounts
¶
Bases: dict
Value -> count, most frequent first (or sorted by value).
A plain dict, marked so that comparison reports pair two value counts
instead of merging them key by key.
Functions:¶
auto_bin_count(n, data_range, iqr)
¶
The number of bins of numpy.histogram_bin_edges(bins="auto").
numpy's "auto" takes the smaller of the Sturges and Freedman-Diaconis bin widths; both depend only on the number of values, their range and their interquartile range, which are computed lazily.
histogram_bin_edges(config, vmin, vmax, n_unique, n, iqr=None)
¶
Bin edges for a histogram of values in [vmin, vmax].
bin_counts(bins, index_counts)
¶
Dense bin counts from sparse bin index -> count pairs.
weighted_histogram(config, values, weights, name='histogram')
¶
A histogram of a small set of distinct values with their counts.
Used for string lengths and file sizes, whose distinct values are few.
chi_square(observed)
¶
Chi-squared goodness-of-fit test against the uniform distribution.
Same result as scipy.stats.chisquare(observed).
imbalance_score(counts, n_classes)
¶
Class imbalance: 1 - entropy / log2(n_classes).
A uniform distribution scores 0, a single dominant class approaches 1. A single class is balanced (0).
imbalance_from_entropy(entropy, n_classes)
¶
Class imbalance from an entropy (base 2) computed lazily.
weighted_median(values, weights)
¶
Median of values repeated weights times (lower median on ties,
averaged when the cumulative weight lands exactly on the half).
length_summary(lengths, counts)
¶
Min, max, mean and median string length from a length histogram.
Args: lengths: distinct lengths. counts: number of values with each length.
unicode_summary(character_counts)
¶
Unicode categories, blocks and scripts of a column's characters.
Args: character_counts: character -> occurrences, most frequent first.
Returns: The character, category, block and script summaries.