Skip to content

Commit 0401b2b

Browse files
authored
Merge pull request #865 from econdb/econdb-fix
Econdb fix
2 parents 1e50626 + 950d5e3 commit 0401b2b

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

docs/source/remote_data.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Currently the following sources are supported:
3030
- :ref:`Tiingo<remote_data.tiingo>`
3131
- :ref:`IEX<remote_data.iex>`
3232
- :ref:`Alpha Vantage<remote_data.alphavantage>`
33+
- :ref:`Econdb<remote_data.econdb>`
3334
- :ref:`Enigma<remote_data.enigma>`
3435
- :ref:`Quandl<remote_data.quandl>`
3536
- :ref:`St.Louis FED (FRED)<remote_data.fred>`
@@ -298,14 +299,36 @@ Econdb
298299
official statistical agencies. Free API allows access to the complete
299300
Econdb database of time series aggregated into datasets.
300301

301-
.. ipython:: python
302+
Reading data for a single series such as the `RGDP <https://www.econdb.com/series/RGDPUS/>`__
303+
for United States, is as simple as taking the ticker segment from the URL path
304+
(``RGDPUS`` in https://www.econdb.com/series/RGDPUS/) and passing it in like:
305+
306+
.. code-block:: ipython
302307
303308
import os
304309
import pandas_datareader.data as web
305310
306311
f = web.DataReader('ticker=RGDPUS', 'econdb')
307312
f.head()
308313
314+
The code snippet for exporting the whole dataset, or its filtered down subset,
315+
can be generated by using the Export -> Pandas Python3 functionality
316+
on any of the numerous datasets available,
317+
such as the Eurostat's `GDP and main components <https://www.econdb.com/dataset/NAMQ_10_GDP>`__
318+
319+
.. code-block:: ipython
320+
321+
import os
322+
import pandas_datareader.data as web
323+
324+
df = web.DataReader('dataset=NAMQ_10_GDP&v=Geopolitical entity (reporting)&h=TIME&from=2018-05-01&to=2021-01-01&GEO=[AL,AT,BE,BA,BG,HR,CY,CZ,DK,EE,EA19,FI,FR,DE,EL,HU,IS,IE,IT,XK,LV,LT,LU,MT,ME,NL,MK,NO,PL,PT,RO,RS,SK,SI,ES,SE,CH,TR,UK]&NA_ITEM=[B1GQ]&S_ADJ=[SCA]&UNIT=[CLV10_MNAC]', 'econdb')
325+
df.columns
326+
327+
Datasets can be located through Econdb's `search <https://www.econdb.com/search>`__
328+
engine, or discovered by exploring the `tree <https://www.econdb.com/tree/>`__
329+
of available statistical sources.
330+
331+
309332
.. _remote_data.econdb:
310333

311334
Enigma

pandas_datareader/econdb.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ class EcondbReader(_BaseReader):
1010
_format = None
1111
_show = "labels"
1212

13+
def __init__(self, *args, **kwargs):
14+
super().__init__(**kwargs)
15+
params = dict(s.split("=") for s in self.symbols.split("&"))
16+
if "from" in params and not kwargs.get("start"):
17+
self.start = pd.to_datetime(params["from"], format="%Y-%m-%d")
18+
if "to" in params and not kwargs.get("end"):
19+
self.end = pd.to_datetime(params["to"], format="%Y-%m-%d")
20+
1321
@property
1422
def url(self):
1523
"""API URL"""
@@ -21,7 +29,7 @@ def url(self):
2129
)
2230

2331
def read(self):
24-
""" read one data from specified URL """
32+
"""read one data from specified URL"""
2533
results = self.session.get(self.url).json()["results"]
2634
df = pd.DataFrame({"dates": []}).set_index("dates")
2735

pandas_datareader/tests/test_econdb.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import numpy as np
22
import pandas as pd
3-
from pandas import testing as tm
43
import pytest
4+
from pandas import testing as tm
55

66
from pandas_datareader import data as web
77

88
pytestmark = pytest.mark.stable
99

1010

1111
class TestEcondb(object):
12+
def test_infer_start_end_from_symbols(self):
13+
df = web.DataReader(
14+
(
15+
"dataset=NAMQ_10_GDP&v=Geopolitical entity (reporting)"
16+
"&h=TIME&from=2010-02-01&to=2018-10-01&GEO=[AL,AT,BE,BA,"
17+
"BG,HR,CY,CZ,DK,EE,EA19,FI,FR,DE,EL,HU,IS,IE,IT,XK,LV,LT,"
18+
"LU,MT,ME,NL,MK,NO,PL,PT,RO,RS,SK,SI,ES,SE,CH,TR,UK]"
19+
"&NA_ITEM=[B1GQ]&S_ADJ=[SCA]&UNIT=[CLV10_MNAC]"
20+
),
21+
"econdb",
22+
)
23+
assert df.index[0].year == 2010
24+
assert df.index[-1].year == 2018
25+
1226
def test_get_cdh_e_fos(self):
1327
# EUROSTAT
1428
# Employed doctorate holders in non managerial and non professional
@@ -38,7 +52,7 @@ def test_get_tourism(self):
3852
# TOURISM_INBOUND
3953

4054
df = web.DataReader(
41-
"dataset=OE_TOURISM_INBOUND&COUNTRY=JPN,USA&" "VARIABLE=INB_ARRIVALS_TOTAL",
55+
"dataset=OE_TOURISM_INBOUND&COUNTRY=JPN,USA&VARIABLE=INB_ARRIVALS_TOTAL",
4256
"econdb",
4357
start=pd.Timestamp("2008-01-01"),
4458
end=pd.Timestamp("2012-01-01"),
@@ -79,7 +93,6 @@ def test_bls(self):
7993
assert df.loc["2010-05-01"][0] == 217.3
8094

8195
def test_australia_gdp(self):
82-
8396
df = web.DataReader(
8497
"dataset=ABS_GDP&to=2019-09-01&from=1959-09-01&h=TIME&v=Indicator", "econdb"
8598
)

0 commit comments

Comments
 (0)