Implementation:Online ml River Utils Pretty
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Online_Learning, Output_Formatting |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Human-readable formatting utilities for displaying data sizes and tables.
Description
Provides humanize_bytes for converting byte counts to readable formats (B, KiB, MiB, etc.) and print_table for creating formatted text tables from headers and columns. Used throughout River for user-friendly output display.
Usage
Use for displaying model sizes, memory usage, or any metrics in human-readable format. Essential for reporting and debugging.
Code Reference
Source Location
- Repository: Online_ml_River
- File: river/utils/pretty.py
Signature
def humanize_bytes(n_bytes: int) -> str:
...
def print_table(
headers: list[str],
columns: list[list[str]],
order: list[int] | None = None,
):
...
Import
from river import utils
Usage Examples
from river import utils
# Humanize byte sizes
print(utils.pretty.humanize_bytes(1024)) # "1 KiB"
print(utils.pretty.humanize_bytes(1536)) # "1.5 KiB"
print(utils.pretty.humanize_bytes(1048576)) # "1 MiB"
print(utils.pretty.humanize_bytes(5000000)) # "4.77 MiB"
# Print tables
headers = ['Model', 'Accuracy', 'Time']
columns = [
['Model A', 'Model B', 'Model C'],
['0.85', '0.87', '0.83'],
['1.2s', '2.1s', '0.9s']
]
table = utils.pretty.print_table(headers, columns)
print(table)
# Output:
# Model Accuracy Time
# Model A 0.85 1.2s
# Model B 0.87 2.1s
# Model C 0.83 0.9s
# Custom order
table_ordered = utils.pretty.print_table(
headers, columns, order=[2, 0, 1] # C, A, B
)
print(table_ordered)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment