Skip to content

ENH: add freq parameter to _BaseReader #199

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion pandas_datareader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class _BaseReader(object):
_chunk_size = 1024 * 1024
_format = 'string'

def __init__(self, symbols, start=None, end=None,
def __init__(self, symbols, start=None, end=None, freq=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise ValueError if freq is not None or "M"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be that the base datareader should accept all of the valid pandas/datetime freq strings ('H', 'M', 'Q', 'A',...) and the specific modules for wb or oecd etc should then determine what is suitable for the particular data source? For instance World Bank offers monthly data, quarterly data, and annual data for the various data sources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to care values which is not implemented ATM from user's point of view. Also, pls move freq to WorldBankReader as other readers don't use it.

NOTE: Some other readers have interval kw which also accept frequency-like. It may better to use the same word but not sure as I'm not native English speaker.

retry_count=3, pause=0.1, session=None):
self.symbols = symbols

start, end = self._sanitize_dates(start, end)
self.start = start
self.end = end
self.freq = freq

if not isinstance(retry_count, int) or retry_count < 0:
raise ValueError("'retry_count' must be integer larger than 0")
Expand Down
8 changes: 6 additions & 2 deletions pandas_datareader/wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class WorldBankReader(_BaseReader):
_format = 'json'

def __init__(self, symbols=None, countries=None,
start=None, end=None,
start=None, end=None, freq=None,
retry_count=3, pause=0.001, session=None, errors='warn'):

if symbols is None:
Expand All @@ -126,7 +126,7 @@ def __init__(self, symbols=None, countries=None,
symbols = [symbols]

super(WorldBankReader, self).__init__(symbols=symbols,
start=start, end=end,
start=start, end=end, freq=freq,
retry_count=retry_count,
pause=pause, session=session)

Expand Down Expand Up @@ -154,6 +154,10 @@ def url(self):

@property
def params(self):
if self.freq == 'M':
return {'date': '{0}M{1:02d}:{2}M{3:02d}'.format(self.start.year,
self.start.month, self.end.year, self.end.month),
'per_page': 25000, 'format': 'json'}
return {'date': '{0}:{1}'.format(self.start.year, self.end.year),
'per_page': 25000, 'format': 'json'}

Expand Down