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

Column type casting based on values #881

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next release

- [#881](https://github.com/IAMconsortium/pyam/pull/881) Column type casting based on values
- [#880](https://github.com/IAMconsortium/pyam/pull/880) Use `pd.Series.iloc[pos]` for forward-compatibility
- [#877](https://github.com/IAMconsortium/pyam/pull/xxx) Support `engine` and other `pd.ExcelFile` keywords.

# Release v2.2.4
Expand Down
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