From cb8ccf55fd371bd96662a4b632f8c5075a35edec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=20Pfl=C3=BCger?= Date: Mon, 8 Jan 2024 15:43:42 +0100 Subject: [PATCH] style: fix some warnings --- unfccc_di_api/unfccc_di_api.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/unfccc_di_api/unfccc_di_api.py b/unfccc_di_api/unfccc_di_api.py index 0cc3195..a07cb5a 100644 --- a/unfccc_di_api/unfccc_di_api.py +++ b/unfccc_di_api/unfccc_di_api.py @@ -299,11 +299,11 @@ def __init__( try: parties_raw = self._get(f"parties/{party_category}") - except requests.JSONDecodeError: + except requests.JSONDecodeError as e: raise RuntimeError( "Access to the UNFCCC API denied - see" " https://github.com/pik-primap/unfccc_di_api#warning for solutions" - ) + ) from e parties_entries = [] for entry in parties_raw: if entry["categoryCode"] == party_category and entry["name"] != "Groups": @@ -469,7 +469,7 @@ def query( "try `UNFCCCSingleCategoryApiReader.parties` for a list of" " valid codes" ) - raise ValueError(f"Unknown party `{code}`, {help}!") + raise ValueError(f"Unknown party `{code}`, {help}!") from None # always query all years year_ids = list(self.years.index) @@ -584,9 +584,8 @@ def _parse_raw_answer( data.append(row) df = pd.DataFrame(data) - df.sort_values( + df = df.sort_values( ["party", "category", "classification", "measure", "gas", "unit", "year"], - inplace=True, ) df.drop_duplicates(inplace=True) df.reset_index(inplace=True, drop=True) @@ -659,7 +658,7 @@ def _name_id(df, name: str, key: str = "name") -> int: try: return int(df[df[key] == name].index[0]) except IndexError: - raise KeyError(name) + raise KeyError(name) from None def show_category_hierarchy(self) -> None: """Print the hierarchy of categories and their IDs."""