Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quant plot hotfixes #809

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pyam/compute.py
Expand Up @@ -25,7 +25,8 @@
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 @@
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 @@
raise ValueError("weights pd.Series must have name 'weight'")

df = self_df.timeseries()
if drop_zeros:
df = df[~(df == 0).all(axis=1)]

Check warning on line 79 in pyam/compute.py

View check run for this annotation

Codecov / codecov/patch

pyam/compute.py#L79

Added line #L79 was not covered by tests
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
Expand Up @@ -710,8 +710,7 @@
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))

Check warning on line 713 in pyam/plotting.py

View check run for this annotation

Codecov / codecov/patch

pyam/plotting.py#L713

Added line #L713 was not covered by tests
kwargs["palette"] = palette
else:
df.sort_values(by, inplace=True)
Expand Down