climate_ref.cli._utils
#
OutputFormat
#
df_to_table(df, max_col_count=-1)
#
Convert a DataFrame to a rich Table instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to convert |
required |
max_col_count
|
int
|
Maximum number of columns to display If the DataFrame has more columns than this, the excess columns will be truncated If set to -1, all columns will be displayed. For very wide DataFrames, then this may result in no values at all being displayed if the column-width ends up being less than 1 char. |
-1
|
Returns:
| Type | Description |
|---|---|
Rich Table instance representing the DataFrame
|
|
Source code in packages/climate-ref/src/climate_ref/cli/_utils.py
format_size(size_bytes)
#
Format file size in human-readable form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size_bytes
|
int | float
|
Size in bytes |
required |
Returns:
| Type | Description |
|---|---|
str
|
Human-readable size string (e.g., "1.5 MB") |
Source code in packages/climate-ref/src/climate_ref/cli/_utils.py
parse_facet_filters(filters)
#
Parse facet filters from key=value format into a dictionary.
Multiple values for the same key are collected into a list (OR logic). Different keys are ANDed together when used for filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
list[str] | None
|
List of filter strings in 'key=value' format.
Multiple entries with the same key are ORed
(e.g., |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dictionary mapping facet keys to lists of allowed values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a filter string is not in valid 'key=value' format |
Examples:
>>> parse_facet_filters(["source_id=GFDL-ESM4", "variable_id=tas"])
{'source_id': ['GFDL-ESM4'], 'variable_id': ['tas']}
Source code in packages/climate-ref/src/climate_ref/cli/_utils.py
pretty_print_df(df, console=None)
#
Pretty print a DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to print |
required |
console
|
Console | None
|
Console to use for printing If not provided, a new Console instance will be created |
None
|
Source code in packages/climate-ref/src/climate_ref/cli/_utils.py
render_dataframe(df, console=None, output_format=OutputFormat.table)
#
Render a DataFrame as either a rich table or machine-readable JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to render |
required |
console
|
Console | None
|
Console to use for table output (ignored for JSON) |
None
|
output_format
|
OutputFormat
|
Unlike the table output, the JSON output is not truncated and does not drop duplicate rows, so it always contains the full values (e.g. complete IDs and paths) and is suitable for scripting. |
table
|