ValueWithMetadata#

class mobgap.utils.tables.ValueWithMetadata(
value: float,
metadata: dict[str, Any] | None = None,
precision: int = 2,
)[source]#

A base class to represent a value with associated metadata.

This can be used as a value within a pandas DataFrame, allowing for custom formatting. For this create a subclass that implements the __str__ and _repr_html_ methods. The main value provided is still used for comparisons, so you can use this class while allowing for sorting and filtering.

Methods

html_styler(st)

Apply HTML styling to the DataFrame using the custom HTML representation.

style_html(value)

Return a string representation of the value for styling purposes.

__init__(
value: float,
metadata: dict[str, Any] | None = None,
precision: int = 2,
) None[source]#

Initialize the ValueWithMetadata object.

Parameters:
value

The value to be stored.

metadata

Optional metadata associated with the value.

precision

The number of decimal places to use for formatting the value.

classmethod html_styler(
st: Styler,
) Styler[source]#

Apply HTML styling to the DataFrame using the custom HTML representation.

classmethod style_html(value: Any) Any[source]#

Return a string representation of the value for styling purposes.