Skip to content

Commit 06751a0

Browse files
committed
Fix pandas FutureWarning: "Passing literal html to 'read_html' is deprecated"
This addresses ranaroussi#1685 (`institutional_holders`) and also `get_earnings_dates()`. Pandas issue is found here: pandas-dev/pandas#53767 and the change in code here: https://github.com/pandas-dev/pandas/blob/5cedf87cccd77c7b4b6aaa64bfec98b32b512f68/pandas/io/html.py#L1238 As for legacy Python 2.7 support: `io.StringIO` seems to be supported in the versions I tested. See https://docs.python.org/2/library/io.html
1 parent 308e58b commit 06751a0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

yfinance/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from __future__ import print_function
2323

2424
import datetime as _datetime
25+
from io import StringIO
2526
import json as _json
2627
import logging
2728
import time as _time
@@ -2090,7 +2091,7 @@ def get_earnings_dates(self, limit=12, proxy=None) -> Optional[pd.DataFrame]:
20902091
"the issue. Thank you for your patience.")
20912092

20922093
try:
2093-
data = pd.read_html(data)[0]
2094+
data = pd.read_html(StringIO(data))[0]
20942095
except ValueError:
20952096
if page_offset == 0:
20962097
# Should not fail on first page

yfinance/scrapers/holders.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from io import StringIO
2+
13
import pandas as pd
24

35
from yfinance.data import TickerData
@@ -36,7 +38,7 @@ def _scrape(self, proxy):
3638
ticker_url = f"{self._SCRAPE_URL_}/{self._data.ticker}"
3739
try:
3840
resp = self._data.cache_get(ticker_url + '/holders', proxy=proxy)
39-
holders = pd.read_html(resp.text)
41+
holders = pd.read_html(StringIO(resp.text))
4042
except Exception:
4143
holders = []
4244

0 commit comments

Comments
 (0)