From 98affc19896b23c3e00003993c953bf64d1ffc56 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Sun, 28 Jan 2024 08:22:22 +0100 Subject: [PATCH 1/2] add capability to drop 0-only values in quanties which can skew statistics --- pyam/compute.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyam/compute.py b/pyam/compute.py index 8e72187a1..645790a1a 100644 --- a/pyam/compute.py +++ b/pyam/compute.py @@ -25,7 +25,8 @@ def __init__(self, df): self._df = df def quantiles( - self, quantiles, weights=None, level=["model", "scenario"], append=False + self, quantiles, weights=None, level=["model", "scenario"], drop_zeros=False, + append=False ): """Compute the optionally weighted quantiles of data grouped by `level`. @@ -44,6 +45,8 @@ def quantiles( Series indexed by `level` level : collection, optional The index columns to compute quantiles over + drop_zeros : bool, optional + Whether to drop data rows if all elements are 0 append : bool, optional Whether to append computed timeseries data to this instance. @@ -72,6 +75,8 @@ def quantiles( raise ValueError("weights pd.Series must have name 'weight'") df = self_df.timeseries() + if drop_zeros: + df = df[~(df == 0).all(axis=1)] model = ( "Quantiles" if weights is None else "Weighted Quantiles" ) # can make this a kwarg From 10ed090a8d9574db887427bb9f4fdac075d681fb Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Sun, 28 Jan 2024 08:23:33 +0100 Subject: [PATCH 2/2] get rid of inplace call for box plots which was causing problems --- pyam/plotting.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyam/plotting.py b/pyam/plotting.py index c98377042..78e0ec7b6 100644 --- a/pyam/plotting.py +++ b/pyam/plotting.py @@ -710,8 +710,7 @@ def box(df, y="value", x=None, by=None, legend=True, title=None, ax=None, **kwar if "palette" not in kwargs and "color" in rc and by in rc["color"]: # TODO this only works if all categories are defined in run_control palette = rc["color"][by] - df[by] = df[by].astype("category") - df[by].cat.set_categories(list(palette), inplace=True) + df[by] = df[by].astype("category").cat.set_categories(list(palette)) kwargs["palette"] = palette else: df.sort_values(by, inplace=True)