diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 442938b..8fcd54c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,12 @@ Changelog ========= +4.0.1 (2024-01-08) +------------------ + +* Use data released until 2023-01-08 when using the ZenodoReader. +* Support python 3.12. + 4.0.0 (2023-07-18) ------------------ @@ -11,7 +17,6 @@ Changelog * Use data released until 2023-07-18 when using the ZenodoReader. * Build the documentation on ReadTheDocs using newer Python and Sphinx versions. - 3.0.2 (2022-12-13) ------------------ diff --git a/unfccc_di_api/unfccc_di_api.py b/unfccc_di_api/unfccc_di_api.py index b189bd5..a07cb5a 100644 --- a/unfccc_di_api/unfccc_di_api.py +++ b/unfccc_di_api/unfccc_di_api.py @@ -93,8 +93,8 @@ class ZenodoReader: def __init__( self, *, - url: str = "doi:10.5281/zenodo.8159736/parquet-only.zip", - known_hash: str = "md5:95d98404f642ed2b684594abba8934ba", + url: str = "doi:10.5281/zenodo.10470862/parquet-only.zip", + known_hash: str = "md5:52dd6cc26f1c2eb3f8204c6a78d2e7ba", ): self._zipfile_path = pooch.retrieve(url=url, known_hash=known_hash) self._zipfile = zipfile.ZipFile(self._zipfile_path) @@ -109,7 +109,7 @@ def _get_party_data(self, *, party: str) -> pd.DataFrame: try: fname = fnames[0] except IndexError: - raise ValueError(f"Unknown party: {party}.") + raise ValueError(f"Unknown party: {party}.") from None with self._zipfile.open(fname) as fd: return pd.read_parquet(fd) @@ -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."""