perun.io.util

IO Util.

Classes

NumpyEncoder

Json Numpy object encoder.

Functions

dataframe_to_markdown(→ str)

Render a DataFrame as a GitHub-flavoured markdown pipe table.

getTFactorMag(→ Tuple[float, ...)

Get transformation factor and magnitude to improve string formating.

value2ValueUnitStr(→ str)

Return a printable representation as [Value:.3f][mag][unit] (e.g. 3.05mV) of the value based on its metric metadata.

value2MeanStdStr(→ str)

Return a printable representation as [Value:.3f]±[std:.3f][mag][unit] (e.g. 3.05±0.1mV) of the value based on its metric metadata.

raw_metric_stats(...)

Compute (min, mean, max, metadata) for a metric from raw sensor data.

Module Contents

perun.io.util.dataframe_to_markdown(df: pandas.DataFrame, stralign: str = 'right') str[source]

Render a DataFrame as a GitHub-flavoured markdown pipe table.

This is a dependency-free replacement for DataFrame.to_markdown (which requires the optional tabulate package). It reproduces the previous output style used in perun reports: a header row, a separator row, and one row per record, with cells aligned according to stralign.

Parameters:
  • df (pandas.DataFrame) – Table to render. The index is not included.

  • stralign (str, optional) – Column alignment, one of "right", "left" or "center". Defaults to "right" to match the historical report format.

Returns:

The markdown table as a string (no trailing newline).

Return type:

str

perun.io.util.getTFactorMag(value: perun.data_model.measurement_type.Number, metric_md: perun.data_model.measurement_type.MetricMetaData) Tuple[float, perun.data_model.measurement_type.Magnitude][source]

Get transformation factor and magnitude to improve string formating.

Parameters:
Returns:

Scaling factor and Magnitude Enum

Return type:

Tuple[float, Magnitude]

perun.io.util.value2ValueUnitStr(value: perun.data_model.measurement_type.Number, metric_md: perun.data_model.measurement_type.MetricMetaData) str[source]

Return a printable representation as [Value:.3f][mag][unit] (e.g. 3.05mV) of the value based on its metric metadata.

Parameters:
Returns:

String represenation

Return type:

str

perun.io.util.value2MeanStdStr(stats: perun.data_model.data.Stats) str[source]

Return a printable representation as [Value:.3f]±[std:.3f][mag][unit] (e.g. 3.05±0.1mV) of the value based on its metric metadata.

Parameters:
  • stats (Stats obj) – Stats to apply formating to.

  • metric_md (MetricMetaData) – Value metadata.

Returns:

String represenation

Return type:

str

perun.io.util.raw_metric_stats(node: Any, metric_type: Any) Tuple[perun.data_model.measurement_type.Number, perun.data_model.measurement_type.Number, perun.data_model.measurement_type.Number, perun.data_model.measurement_type.MetricMetaData] | None[source]

Compute (min, mean, max, metadata) for a metric from raw sensor data.

The statistics are taken directly from the underlying sensor time-series found beneath node (a host, device-group or run node), which is exactly the raw data recorded during monitoring. Returns None when the metric has no per-sample series (e.g. RUNTIME, ENERGY) or no matching sensor data is available.

Parameters:
  • node (DataNode) – Any node in the tree; its sensor descendants are searched.

  • metric_type (MetricType) – The metric whose raw statistics are requested.

Returns:

(min, mean, max, metric_md) in base magnitude, or None.

Return type:

tuple | None

class perun.io.util.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.JSONEncoder

Json Numpy object encoder.

default(o: Any) Any[source]

Encode an object to a JSON-serializable format, handling NumPy types.

Parameters:

o (Any) – The object to encode.

Returns:

The JSON-serializable representation of the input object.

Return type:

Any

Raises:

TypeError – If the object cannot be encoded to a supported format.

Notes

This method specifically handles NumPy integer, floating, ndarray, and dtype objects, converting them to standard Python types or string representations. For other types, the superclass’s default method is called.