diff --git a/pyam/core.py b/pyam/core.py index 168bf4c28..81539a16c 100755 --- a/pyam/core.py +++ b/pyam/core.py @@ -989,6 +989,7 @@ def categorize( # update meta dataframe self._new_meta_column(name) + self.meta[name] = self.meta[name].astype(object) self.meta.loc[idx, name] = value msg = "{} scenario{} categorized as `{}: {}`" logger.info(msg.format(len(idx), "" if len(idx) == 1 else "s", name, value)) diff --git a/pyam/statistics.py b/pyam/statistics.py index 44e94149c..673dc3709 100644 --- a/pyam/statistics.py +++ b/pyam/statistics.py @@ -290,6 +290,7 @@ def format_rows( count = max( [i for i in row.loc[(slice(None), slice(None), "count")] if not np.isnan(i)] ) + ret = ret.astype(object) ret.loc[("count", "")] = (f"{count:.0f}") if count > 1 else "" # set upper and lower for the range diff --git a/tests/test_core.py b/tests/test_core.py index 73a56e05a..371b6994f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -92,6 +92,7 @@ def test_init_df_with_duplicates_raises(test_df): def test_init_df_with_illegal_values_raises(test_pd_df, illegal_value): # values that cannot be cast to float should raise a value error and be specified by # index for user + test_pd_df[2005] = test_pd_df[2005].astype(object) test_pd_df.loc[0, 2005] = illegal_value msg = ( f'.*string "{illegal_value}" in `data`:'