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

Improve exception handling #65

Open
chriscarrollsmith opened this issue Jan 21, 2025 · 0 comments
Open

Improve exception handling #65

chriscarrollsmith opened this issue Jan 21, 2025 · 0 comments

Comments

@chriscarrollsmith
Copy link
Collaborator

chriscarrollsmith commented Jan 21, 2025

Investigate and implement different and more appropriate exception types, as we're currently handling too many different cases with 'ValueError'.

Also, it looks like when the API returns HTML instead of JSON, we're not always catching it, as in this error case from imf_databases:


KeyError Traceback (most recent call last)
Cell In[3], line 9
7 databases = pd.read_parquet(cache_path)
8 else:
----> 9 databases = imfp.imf_databases()
10 os.makedirs("data", exist_ok=True)
11 databases.to_parquet(cache_path)

File ~\Software\Python\imfp\imfp\data.py:37, in imf_databases(times)
32 url = "http://dataservices.imf.org/REST/SDMX_JSON.svc/Dataflow"
33 raw_dl = _download_parse(url, times)
35 database_id = [
36 dataflow["KeyFamilyRef"]["KeyFamilyID"]
---> 37 for dataflow in raw_dl["Structure"]["Dataflows"]["Dataflow"]
38 ]
40 description = [
41 dataflow["Name"]["#text"]
42 for dataflow in raw_dl["Structure"]["Dataflows"]["Dataflow"]
43 ]
44 database_list = DataFrame({"database_id": database_id, "description": description})

KeyError: 'Structure'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant