Skip to content

Commit fd749a7

Browse files
authored
Merge pull request #450 from bashtage/immediate-deprecation
CLN/REF: Mark deprecated API
2 parents 3156d71 + de6387d commit fd749a7

File tree

7 files changed

+70
-35
lines changed

7 files changed

+70
-35
lines changed

pandas_datareader/data.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from pandas_datareader.edgar import EdgarIndexReader
99
from pandas_datareader.enigma import EnigmaReader
1010
from pandas_datareader.eurostat import EurostatReader
11+
from pandas_datareader.exceptions import ImmediateDeprecationError, \
12+
DEP_ERROR_MSG
1113
from pandas_datareader.famafrench import FamaFrenchReader
1214
from pandas_datareader.fred import FredReader
1315
from pandas_datareader.google.daily import GoogleDailyReader
@@ -51,6 +53,7 @@ def get_data_google(*args, **kwargs):
5153

5254

5355
def get_data_yahoo(*args, **kwargs):
56+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
5457
return YahooDailyReader(*args, **kwargs).read()
5558

5659

@@ -59,14 +62,17 @@ def get_data_enigma(*args, **kwargs):
5962

6063

6164
def get_data_yahoo_actions(*args, **kwargs):
65+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
6266
return YahooActionReader(*args, **kwargs).read()
6367

6468

6569
def get_quote_yahoo(*args, **kwargs):
70+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
6671
return YahooQuotesReader(*args, **kwargs).read()
6772

6873

6974
def get_quote_google(*args, **kwargs):
75+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google Quotes'))
7076
return GoogleQuotesReader(*args, **kwargs).read()
7177

7278

@@ -210,17 +216,16 @@ def DataReader(name, data_source=None, start=None, end=None,
210216
"""
211217
Imports data from a number of online sources.
212218
213-
Currently supports Yahoo! Finance, Google Finance, St. Louis FED (FRED),
214-
Kenneth French's data library, and the SEC's EDGAR Index.
219+
Currently supports Google Finance, St. Louis FED (FRED),
220+
and Kenneth French's data library, among others.
215221
216222
Parameters
217223
----------
218224
name : str or list of strs
219-
the name of the dataset. Some data sources (yahoo, google, fred) will
225+
the name of the dataset. Some data sources (google, fred) will
220226
accept a list of names.
221227
data_source: {str, None}
222-
the data source ("yahoo", "yahoo-actions", "yahoo-dividends",
223-
"google", "fred", "ff", or "edgar-index")
228+
the data source ("google", "fred", "ff")
224229
start : {datetime, None}
225230
left boundary for range (defaults to 1/1/2010)
226231
end : {datetime, None}
@@ -237,14 +242,6 @@ def DataReader(name, data_source=None, start=None, end=None,
237242
238243
Examples
239244
----------
240-
241-
# Data from Yahoo! Finance
242-
gs = DataReader("GS", "yahoo")
243-
244-
# Corporate Actions (Dividend and Split Data)
245-
# with ex-dates from Yahoo! Finance
246-
gs = DataReader("GS", "yahoo-actions")
247-
248245
# Data from Google Finance
249246
aapl = DataReader("AAPL", "google")
250247
@@ -263,23 +260,23 @@ def DataReader(name, data_source=None, start=None, end=None,
263260
ff = DataReader("F-F_Research_Data_Factors_weekly", "famafrench")
264261
ff = DataReader("6_Portfolios_2x3", "famafrench")
265262
ff = DataReader("F-F_ST_Reversal_Factor", "famafrench")
266-
267-
# Data from EDGAR index
268-
ed = DataReader("full", "edgar-index")
269-
ed2 = DataReader("daily", "edgar-index")
270263
"""
271264
if data_source == "yahoo":
265+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Daily'))
272266
return YahooDailyReader(symbols=name, start=start, end=end,
273267
adjust_price=False, chunksize=25,
274268
retry_count=retry_count, pause=pause,
275269
session=session).read()
276270

277271
elif data_source == "yahoo-actions":
272+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
278273
return YahooActionReader(symbols=name, start=start, end=end,
279274
retry_count=retry_count, pause=pause,
280275
session=session).read()
281276

282277
elif data_source == "yahoo-dividends":
278+
comp = 'Yahoo Dividends'
279+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format(comp))
283280
return YahooDivReader(symbols=name, start=start, end=end,
284281
adjust_price=False, chunksize=25,
285282
retry_count=retry_count, pause=pause,
@@ -337,6 +334,7 @@ def DataReader(name, data_source=None, start=None, end=None,
337334
retry_count=retry_count, pause=pause,
338335
session=session).read()
339336
elif data_source == "edgar-index":
337+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('EDGAR'))
340338
return EdgarIndexReader(symbols=name, start=start, end=end,
341339
retry_count=retry_count, pause=pause,
342340
session=session).read()
@@ -364,8 +362,10 @@ def Options(symbol, data_source=None, session=None):
364362
" data_source) instead", FutureWarning, stacklevel=2)
365363
data_source = "yahoo"
366364
if data_source == "yahoo":
365+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Options'))
367366
return YahooOptions(symbol, session=session)
368367
elif data_source == "google":
368+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google Options'))
369369
return GoogleOptions(symbol, session=session)
370370
else:
371371
raise NotImplementedError("currently only yahoo and google supported")

pandas_datareader/exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@
33

44
class UnstableAPIWarning(Warning):
55
pass
6+
7+
8+
DEP_ERROR_MSG = """
9+
{0} has been immediately deprecated due to large breaks in the API without the
10+
introduction of a stable replacement. Pull Requests to re-enable these data
11+
connectors are welcome.
12+
13+
See https://github.com/pydata/pandas-datareader/issues
14+
"""
15+
16+
17+
class ImmediateDeprecationError(Exception):
18+
pass

pandas_datareader/google/daily.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from pandas_datareader.base import _DailyBaseReader
2+
from pandas_datareader.exceptions import UnstableAPIWarning
23

4+
UNSTABLE_WARNING = """
5+
The Google Finance API has not been stable since late 2017. Requests seem
6+
to fail at random. Failure is especially common when bulk downloading.
7+
"""
38

4-
class GoogleDailyReader(_DailyBaseReader):
59

10+
class GoogleDailyReader(_DailyBaseReader):
611
"""
712
Returns DataFrame/Panel of historical stock prices from symbols, over date
813
range, start to end. To avoid being penalized by Google Finance servers,
@@ -29,6 +34,14 @@ class GoogleDailyReader(_DailyBaseReader):
2934
requests.sessions.Session instance to be used
3035
"""
3136

37+
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
38+
pause=0.001, session=None, chunksize=25):
39+
import warnings
40+
warnings.warn(UNSTABLE_WARNING, UnstableAPIWarning)
41+
super(GoogleDailyReader, self).__init__(symbols, start, end,
42+
retry_count, pause, session,
43+
chunksize)
44+
3245
@property
3346
def url(self):
3447
return 'http://finance.google.com/finance/historical'

pandas_datareader/tests/google/test_options.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import pytest
2-
31
from datetime import date
42

53
import numpy as np
64
import pandas as pd
75
import pandas.util.testing as tm
6+
import pytest
87

98
import pandas_datareader.data as web
9+
from pandas_datareader.exceptions import ImmediateDeprecationError
1010

1111

1212
class TestGoogleOptions(object):
1313

1414
@classmethod
1515
def setup_class(cls):
16-
# GOOG has monthlies
17-
cls.goog = web.Options('GOOG', 'google')
16+
cls.goog = None
17+
18+
def test_deprecation(self):
19+
with pytest.raises(ImmediateDeprecationError):
20+
web.Options('GOOG', 'google')
1821

1922
@pytest.mark.xfail(reason='Parsing error')
2023
def test_get_options_data(self):
@@ -40,8 +43,9 @@ def test_get_options_data(self):
4043
for typ in options.index.levels[2]:
4144
assert typ in ['put', 'call']
4245

46+
@pytest.mark.xfail(reason='Deprecated')
4347
def test_get_options_data_yearmonth(self):
44-
with pytest.raises(NotImplementedError):
48+
with pytest.raises(ImmediateDeprecationError):
4549
self.goog.get_options_data(month=1, year=2016)
4650

4751
@pytest.mark.xfail(reason='Parsing error')
@@ -52,26 +56,32 @@ def test_expiry_dates(self):
5256
assert isinstance(dates, list)
5357
assert all(isinstance(dt, date) for dt in dates)
5458

59+
@pytest.mark.xfail(reason='Deprecated')
5560
def test_get_call_data(self):
5661
with pytest.raises(NotImplementedError):
5762
self.goog.get_call_data()
5863

64+
@pytest.mark.xfail(reason='Deprecated')
5965
def test_get_put_data(self):
6066
with pytest.raises(NotImplementedError):
6167
self.goog.get_put_data()
6268

69+
@pytest.mark.xfail(reason='Deprecated')
6370
def test_get_near_stock_price(self):
6471
with pytest.raises(NotImplementedError):
6572
self.goog.get_near_stock_price()
6673

74+
@pytest.mark.xfail(reason='Deprecated')
6775
def test_get_forward_data(self):
6876
with pytest.raises(NotImplementedError):
6977
self.goog.get_forward_data([1, 2, 3])
7078

79+
@pytest.mark.xfail(reason='Deprecated')
7180
def test_get_all_data(self):
7281
with pytest.raises(NotImplementedError):
7382
self.goog.get_all_data()
7483

84+
@pytest.mark.xfail(reason='Deprecated')
7585
def test_get_options_data_with_year(self):
7686
with pytest.raises(NotImplementedError):
7787
self.goog.get_options_data(year=2016)

pandas_datareader/tests/test_data.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import pytest
22

3-
import pandas.util.testing as tm
4-
import pandas_datareader.data as web
5-
63
from pandas import DataFrame
74
from pandas_datareader.data import DataReader
85

96

10-
class TestOptionsWarnings(object):
11-
12-
def test_options_source_warning(self):
13-
with tm.assert_produces_warning():
14-
web.Options('aapl')
15-
16-
177
class TestDataReader(object):
188

199
def test_read_google(self):

pandas_datareader/tests/test_edgar.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import pytest
2-
31
import pandas as pd
42
import pandas.util.testing as tm
3+
import pytest
4+
55
import pandas_datareader.data as web
6+
from pandas_datareader.exceptions import ImmediateDeprecationError
67

78

89
class TestEdgarIndex(object):
@@ -13,6 +14,10 @@ def setup_class(cls):
1314
# Disabling tests until re-write.
1415
pytest.skip("Disabling tests until re-write.")
1516

17+
def test_raises(self):
18+
with pytest.raises(ImmediateDeprecationError):
19+
web.DataReader('full', 'edgar-index')
20+
1621
def test_get_full_index(self):
1722
ed = web.DataReader('full', 'edgar-index')
1823
assert len(ed) > 1000

pandas_datareader/yahoo/components.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from pandas import DataFrame
22
from pandas.io.common import urlopen
33

4+
from pandas_datareader.exceptions import ImmediateDeprecationError, \
5+
DEP_ERROR_MSG
6+
47
_URL = 'http://download.finance.yahoo.com/d/quotes.csv?'
58

69

@@ -25,6 +28,7 @@ def _get_data(idx_sym): # pragma: no cover
2528
-------
2629
idx_df : DataFrame
2730
"""
31+
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Components'))
2832
stats = 'snx'
2933
# URL of form:
3034
# http://download.finance.yahoo.com/d/quotes.csv?s=@%5EIXIC&f=snxl1d1t1c1ohgv

0 commit comments

Comments
 (0)