Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pyam/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pyam/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down