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

New data version #95

Merged
merged 3 commits into from
Jan 8, 2024
Merged
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
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 @@
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 @@
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 @@

try:
parties_raw = self._get(f"parties/{party_category}")
except requests.JSONDecodeError:
except requests.JSONDecodeError as e:

Check warning on line 302 in unfccc_di_api/unfccc_di_api.py

View check run for this annotation

Codecov / codecov/patch

unfccc_di_api/unfccc_di_api.py#L302

Added line #L302 was not covered by tests
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 @@
"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 @@
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 @@
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
Loading