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 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)