Skip to content

Commit

Permalink
Changed SDMX backend from pandasdmx to sdmx1 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkgaraujo authored Jun 20, 2024
1 parent b228bf6 commit cb21845
Show file tree
Hide file tree
Showing 11 changed files with 1,246 additions and 648 deletions.
4 changes: 3 additions & 1 deletion 00_augmentation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ warning: false
from __future__ import annotations
import numpy as np
import pandas as pd
import pandasdmx as sdmx
from utils import show_doc
```

Expand Down Expand Up @@ -222,6 +222,8 @@ from gingado.utils import list_all_dataflows
```

```{python}
#| warning: false
dflows = list_all_dataflows()
dflows
```
Expand Down
1 change: 0 additions & 1 deletion 00_benchmark.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ warning: false
from __future__ import annotations
import numpy as np
import pandas as pd
import pandasdmx as sdmx
from utils import show_doc
from gingado.benchmark import ggdBenchmark, ClassificationBenchmark, RegressionBenchmark, TimeSeriesSplit, ShuffleSplit
Expand Down
2 changes: 1 addition & 1 deletion 00_utils.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Or the user can search dataflows by their human-readable name instead of their c

```{python}
dflows[dflows.str.contains('Interest rates', case=False)]
dflows[dflows.str.contains('Interest rate', case=False)]
```

The function `load_SDMX_data` is a convenience function that downloads data from SDMX sources (and any specific dataflows passed as arguments) if they match the key and parameters set by the user.
Expand Down
861 changes: 523 additions & 338 deletions docs/augmentation.html

Large diffs are not rendered by default.

507 changes: 352 additions & 155 deletions docs/benchmark.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/search.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions docs/site_libs/bootstrap/bootstrap-dark.min.css

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions docs/site_libs/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

473 changes: 342 additions & 131 deletions docs/utils.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions gingado/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pandasdmx as sdmx
import sdmx
import datetime
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -135,7 +135,7 @@ def list_all_dataflows(
dflows = {}
for src in sources:
try:
dflows[src] = sdmx.to_pandas(sdmx.Request(src).dataflow().dataflow)
dflows[src] = sdmx.to_pandas(sdmx.Client(src).dataflow().dataflow)
dflows[src] = dflows[src].index if codes_only else dflows[src].index.reset_index()
except:
pass
Expand Down Expand Up @@ -165,15 +165,15 @@ def load_SDMX_data(
A pandas DataFrame with data from SDMX or None if no data matches the sources, keys, and parameters.
"""
data_sdmx = {}
for source in sources.keys():
src_conn = sdmx.Request(source)
for source in list(sources.keys()):
src_conn = sdmx.Client(source)
src_dflows = src_conn.dataflow()
if sources[source] == 'all':
dflows = {k: v for k, v in src_dflows.dataflow.items()}
else:
dflows = {k: v for k, v in src_dflows.dataflow.items() if k in sources[source]}
for dflow in dflows.keys():
if verbose: print(f"Querying data from {source}'s dataflow '{dflow}' - {dflows[dflow].dict()['name']}...")
for dflow in list(dflows.keys()):
if verbose: print(f"Querying data from {source}'s dataflow '{dflow}' - {dflows[dflow]._name}...")
try:
data = sdmx.to_pandas(src_conn.data(dflow, key=keys, params=params), datetime='TIME_PERIOD')
except:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.21
pandas>=1.3.5
pandasdmx>=1.8.1
sdmx1>=2.15.0
scikit-learn>=1.0.2
requests_cache>=0.9.1
matplotlib>=3.5
Expand Down

0 comments on commit cb21845

Please sign in to comment.