From c1a1e6d086f573cbd2e361e5f52ca83148a84b9d Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Fri, 1 Sep 2023 13:54:09 +0200 Subject: [PATCH] Pass name as string instead of method to aggregation --- pyam/aggregation.py | 6 +++--- pyam/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyam/aggregation.py b/pyam/aggregation.py index b571186cd..9f2aa74c8 100644 --- a/pyam/aggregation.py +++ b/pyam/aggregation.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) -def _aggregate(df, variable, components=None, method=np.sum): +def _aggregate(df, variable, components=None, method="sum"): """Internal implementation of the `aggregate` function""" if components is not None: @@ -168,7 +168,7 @@ def _aggregate_region( return _data -def _aggregate_time(df, variable, column, value, components, method=np.sum): +def _aggregate_time(df, variable, column, value, components, method="sum"): """Internal implementation for aggregating data over subannual time""" # default `components` to all entries in `column` other than `value` if components is None: @@ -196,7 +196,7 @@ def _aggregate_time(df, variable, column, value, components, method=np.sum): return _data -def _group_and_agg(df, by, method=np.sum): +def _group_and_agg(df, by, method="sum"): """Group-by & aggregate `pd.Series` by index names on `by`""" cols = df.index.names.difference(to_list(by)) # pick aggregator func (default: sum) diff --git a/pyam/utils.py b/pyam/utils.py index 63ed15c96..5848c3c75 100644 --- a/pyam/utils.py +++ b/pyam/utils.py @@ -47,7 +47,7 @@ "max": np.max, "avg": np.mean, "mean": np.mean, - "sum": np.sum, + "sum": "sum", } @@ -546,7 +546,7 @@ def pattern_match( if is_str(s): pattern = re.compile(escape_regexp(s) + "$" if not regexp else s) depth = True if level is None else find_depth(_data, s, level) - matches |= data.str.match(pattern) & depth + matches |= data.str.match(pattern) & np.array(depth) else: matches = np.logical_or(matches, data == s)