Skip to content

Commit

Permalink
Column type casting based on values
Browse files Browse the repository at this point in the history
  • Loading branch information
quant12345 committed Oct 5, 2024
1 parent e27e90e commit 542d003
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions pyam/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`:'
Expand Down

0 comments on commit 542d003

Please sign in to comment.