Skip to content

Commit

Permalink
Merge pull request #95 from pik-primap/new-data-version
Browse files Browse the repository at this point in the history
New data version
  • Loading branch information
mikapfl authored Jan 8, 2024
2 parents c4168bf + e0358e0 commit aeb065e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand All @@ -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)
------------------

Expand Down
17 changes: 8 additions & 9 deletions unfccc_di_api/unfccc_di_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit aeb065e

Please sign in to comment.