Skip to content

Commit

Permalink
Fix pandas FutureWarning: "Passing literal html to 'read_html' is dep…
Browse files Browse the repository at this point in the history
…recated"

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
  • Loading branch information
mikez committed Nov 9, 2023
1 parent 308e58b commit 06751a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from __future__ import print_function

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

try:
data = pd.read_html(data)[0]
data = pd.read_html(StringIO(data))[0]
except ValueError:
if page_offset == 0:
# Should not fail on first page
Expand Down
4 changes: 3 additions & 1 deletion yfinance/scrapers/holders.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from io import StringIO

import pandas as pd

from yfinance.data import TickerData
Expand Down Expand Up @@ -36,7 +38,7 @@ def _scrape(self, proxy):
ticker_url = f"{self._SCRAPE_URL_}/{self._data.ticker}"
try:
resp = self._data.cache_get(ticker_url + '/holders', proxy=proxy)
holders = pd.read_html(resp.text)
holders = pd.read_html(StringIO(resp.text))
except Exception:
holders = []

Expand Down

0 comments on commit 06751a0

Please sign in to comment.