analog_daddy.mootils
¶
A collection of marimo utility functions.
While marimo is quite feature-rich, these functions are intended to be convenience functions for common tasks that are not yet implemented in marimo. These might be deprecated if they become available in marimo.
df_repr_docstr_clip(df, max_rows=3)
¶
Copy the repr of a polars DataFrame to the clipboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to copy the repr of. |
required |
max_rows
|
int
|
The maximum number of rows to include in the repr. |
3
|
Returns:
| Type | Description |
|---|---|
CopyToClipboard
|
A CopyToClipboard object containing the repr of the DataFrame. |
Examples:
>>> a = pl.DataFrame(
... {"x": [9.0, 11.0], "foo": [10.0, 10.0], "bar": [5.0, 5.0]},
... )
>>> df_repr_docstr_clip(a).text_to_copy.startswith("shape: (2, 3)")
True
Source code in src/analog_daddy/mootils.py
format_mapping_num_to_si(df)
¶
Build a format mapping that renders numeric columns as SI strings.
Intended for the format_mapping argument of mo.ui.table and
mo.ui.dataframe. Columns are matched with cs.numeric() and
rendered with :func:render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame whose numeric columns to map. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Callable]
|
Column name to formatter mapping. |
References
Source code in src/analog_daddy/mootils.py
rich_md(*renderables, console_kwargs=None, print_kwargs=None, export_html_kwargs=None)
¶
A minimal helper function to utilize rich markup within marimo.
Created this for shits-n-giggles. This is in no way complete! I don't use this as much as I would like to, however, in case you have some text, that you would like to keep consistent with your console markup, this might be an option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*renderables
|
RenderableType
|
The renderable objects to be printed using rich. |
()
|
console_kwargs
|
dict[str, Any] | None
|
Keyword arguments to customize the rich Console. |
None
|
print_kwargs
|
dict[str, Any] | None
|
Keyword arguments to customize the rich print method. |
None
|
export_html_kwargs
|
dict[str, Any] | None
|
Keyword arguments to customize the rich export_html method. |
None
|
Returns:
| Type | Description |
|---|---|
Html
|
The HTML representation of the rich renderables. |
Examples:
>>> "font-weight: bold" in rich_md("[bold green]Hello[/] World").text
True
>>> "font-style: italic" in rich_md(
... "[bold]Bold[italic] bold and italic [/bold]italic[/italic]"
... ).text
True
>>> "⚠️" in rich_md(":warning-emoji: you have been warned!").text
True