Skip to content

Commit cdd8b4d

Browse files
OlegShteynbukjreback
authored andcommitted
fix 'null' in lower case as a missing value in the new Yahoo API, make compatible with the older pandas versions (#357)
1 parent 20d16c2 commit cdd8b4d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/source/whatsnew/v0.5.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Bug Fixes
2323
- Test suite fixes for test_get_options_data (:issue:`352`)
2424
- Test suite fixes for test_wdi_download (:issue:`350`)
2525
- avoid monkey patching requests.Session (:issue:`301`)
26+
- :func:`get_data_yahoo` now treats ``'null'`` strings as missing values (:issue:`342`)

pandas_datareader/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def _get_crumb(self, *args):
143143
raise NotImplementedError("Subclass has not implemented method.")
144144

145145
def _read_lines(self, out):
146-
rs = read_csv(out, index_col=0, parse_dates=True, na_values='-')[::-1]
146+
rs = read_csv(out, index_col=0, parse_dates=True,
147+
na_values=('-', 'null'))[::-1]
147148
# Yahoo! Finance sometimes does this awesome thing where they
148149
# return 2 rows for the most recent business day
149150
if len(rs) > 2 and rs.index[-1] == rs.index[-2]: # pragma: no cover

pandas_datareader/tests/yahoo/test_yahoo.py

+13
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ def test_get_data_multiple_symbols(self):
131131
sl = ['AAPL', 'AMZN', 'GOOG']
132132
web.get_data_yahoo(sl, '2012')
133133

134+
@pytest.mark.parametrize('adj_pr', [True, False])
135+
def test_get_data_null_as_missing_data(self, adj_pr):
136+
# TODO: We can't decorate the test function along with
137+
# parametrization because it errors. Investigate this later.
138+
@skip_on_exception(RemoteDataError)
139+
def null_as_missing_data(adj_price):
140+
result = web.get_data_yahoo('SRCE', '20160626', '20160705',
141+
adjust_price=adj_pr)
142+
# sanity checking
143+
assert result.dtypes.all() == np.floating
144+
145+
null_as_missing_data(adj_pr)
146+
134147
@skip_on_exception(RemoteDataError)
135148
def test_get_data_multiple_symbols_two_dates(self):
136149
pan = web.get_data_yahoo(['GE', 'MSFT', 'INTC'], 'JAN-01-12',

0 commit comments

Comments
 (0)