Skip to main content

LossPanel

LossPanel(losses, weights, labels, labels_are_positional, _validated=False)

A validated {model: per-period loss array} panel, plus period labels and per-period weights.

Construction always goes through .from_losses() (wide DataFrame / ndarray / dict of per-model arrays) or .from_forecasts() (long forecast-vs-actual frame, losses computed here). The bare constructor raises – it exists only so the two classmethods and .load() can build an instance after they have already done the validation.

Methods

Name Description
load Deserialize from JSON written by .save(). Labels come back as str regardless of what
save Serialize to JSON. Labels are stringified (str(label)) since JSON has no native

load

LossPanel.load(path)

Deserialize from JSON written by .save(). Labels come back as str regardless of what type they were saved from (see .save()’s docstring) – a round trip is not type-preserving for labels, only value-preserving as text.

save

LossPanel.save(path)

Serialize to JSON. Labels are stringified (str(label)) since JSON has no native Timestamp/date type – a panel built with Timestamp labels loads back with str labels of the same text, not the original type. compare() accounts for this by comparing str(label) on both sides; anything else comparing raw label objects across a save/load boundary must do the same.

Atomic write: writing directly to path would leave a window where a concurrent reader could open a partially-written file and hit a raw JSONDecodeError. The standard write-to-temp-then-os.replace pattern avoids this: the temp file lives in the SAME directory as path (so the replace is on the same filesystem, required for atomicity, and works identically on POSIX and Windows) and is only renamed into place once fully written and flushed. A concurrent reader therefore always sees either the complete old file or the complete new one, never a partial write.