Skip to content

Commit c88c906

Browse files
committed
CLN: Add freq to base
Store freq in base
1 parent 3819261 commit c88c906

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

pandas_datareader/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self, symbols, start=None, end=None, retry_count=3,
5555
self.timeout = timeout
5656
self.pause_multiplier = 1
5757
self.session = _init_session(session, retry_count)
58+
self.freq = freq
5859

5960
def close(self):
6061
""" close my session """

pandas_datareader/tests/test_wb.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import time
2-
import pytest
32

43
import numpy as np
54
import pandas as pd
5+
import pandas.util.testing as tm
6+
import pytest
67
import requests
78

8-
import pandas.util.testing as tm
9+
from pandas_datareader.compat import assert_raises_regex
910
from pandas_datareader.wb import (search, download, get_countries,
1011
get_indicators, WorldBankReader)
11-
from pandas_datareader.compat import assert_raises_regex
1212

1313

1414
class TestWB(object):
@@ -236,41 +236,42 @@ def test_wdi_download_monthly(self):
236236
cntry_codes = 'ALL'
237237
inds = 'COPPER'
238238
result = download(country=cntry_codes, indicator=inds,
239-
start=2011, end=2012, freq='M',errors='ignore')
239+
start=2011, end=2012, freq='M', errors='ignore')
240240
result = result.sort_index()
241241
result = np.round(result, decimals=-3)
242242

243243
expected.index.names = ['country', 'year']
244244
tm.assert_frame_equal(result, expected)
245245

246-
result = WorldBankReader(inds, countries=cntry_codes,
247-
start=2011, end=2012, freq='M', errors='ignore').read()
246+
result = WorldBankReader(inds, countries=cntry_codes, start=2011,
247+
end=2012, freq='M', errors='ignore').read()
248248
result = result.sort_index()
249249
result = np.round(result, decimals=-3)
250250
tm.assert_frame_equal(result, expected)
251251

252252
def test_wdi_download_quarterly(self):
253-
expected = {'DT.DOD.PUBS.CD.US': {('Albania', '2012Q1'): 3240539817.18,
254-
('Albania', '2011Q4'): 3213979715.15,
255-
('Albania', '2011Q3'): 3187681048.95,
256-
('Albania', '2011Q2'): 3248041513.86,
257-
('Albania', '2011Q1'): 3137210567.92}}
253+
code = 'DT.DOD.PUBS.CD.US'
254+
expected = {code: {('Albania', '2012Q1'): 3240539817.18,
255+
('Albania', '2011Q4'): 3213979715.15,
256+
('Albania', '2011Q3'): 3187681048.95,
257+
('Albania', '2011Q2'): 3248041513.86,
258+
('Albania', '2011Q1'): 3137210567.92}}
258259
expected = pd.DataFrame(expected)
259260
# Round, to ignore revisions to data.
260261
expected = np.round(expected, decimals=-3)
261262
expected = expected.sort_index()
262263
cntry_codes = 'ALB'
263264
inds = 'DT.DOD.PUBS.CD.US'
264265
result = download(country=cntry_codes, indicator=inds,
265-
start=2011, end=2012, freq='Q',errors='ignore')
266+
start=2011, end=2012, freq='Q', errors='ignore')
266267
result = result.sort_index()
267268
result = np.round(result, decimals=-3)
268269

269270
expected.index.names = ['country', 'year']
270271
tm.assert_frame_equal(result, expected)
271272

272-
result = WorldBankReader(inds, countries=cntry_codes,
273-
start=2011, end=2012, freq='Q', errors='ignore').read()
273+
result = WorldBankReader(inds, countries=cntry_codes, start=2011,
274+
end=2012, freq='Q', errors='ignore').read()
274275
result = result.sort_index()
275276
result = np.round(result, decimals=-1)
276277
tm.assert_frame_equal(result, expected)

pandas_datareader/wb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def __init__(self, symbols=None, countries=None,
147147
freq_symbols = ['M', 'Q', 'A', None]
148148

149149
if freq not in freq_symbols:
150-
msg = 'The frequency `{0}` is not in the accepted list.'.format(freq)
150+
msg = 'The frequency `{0}` is not in the accepted ' \
151+
'list.'.format(freq)
151152
raise ValueError(msg)
152153

153154
self.freq = freq

0 commit comments

Comments
 (0)