Skip to content

Commit

Permalink
Merge pull request #239 from Gamrix/master
Browse files Browse the repository at this point in the history
Removing unmaintained pandas_datareader
  • Loading branch information
timkpaine authored Jul 1, 2024
2 parents ec2e5c6 + 54c986a commit 174a0cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
44 changes: 12 additions & 32 deletions ffn/data.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import warnings
from typing import Sequence, Union
import ffn

import pandas as pd
import yfinance
from packaging.version import Version
from pandas_datareader import data as pdata

import ffn

# import ffn.utils as utils
from . import utils

# This is a temporary fix until pandas_datareader 0.7 is released.
# pandas 0.23 has moved is_list_like from common to api.types, hence the monkey patch
if Version(pd.__version__) > Version("0.23.0"):
pd.core.common.is_list_like = pd.api.types.is_list_like


@utils.memoize
def get(
Expand Down Expand Up @@ -103,42 +99,26 @@ def get(
return df


@utils.memoize
def web(ticker: str, field=None, start=None, end=None, mrefresh=False, source="yahoo"):
"""
Data provider wrapper around pandas.io.data provider. Provides
memoization.
"""
if source == "yahoo" and field is None:
field = "Adj Close"

tmp = _download_web(ticker, data_source=source, start=start, end=end)

if tmp is None:
raise ValueError("failed to retrieve data for %s:%s" % (ticker, field))

if field:
return tmp[field]
else:
return tmp


@utils.memoize
def _download_web(name: str, **kwargs) -> pd.DataFrame:
"""
Thin wrapper to enable memoization
"""
return pdata.DataReader(name, **kwargs)
if source == "yahoo":
warnings.warn("web function is deprecated, as , use yf() instead")
return yf(ticker, field, start, end, mrefresh)
raise Exception("""pandas_datareader data readers are unmaintained and mostly broken, If you
still want them, go import the datareader directly from that library.
https://github.com/pydata/pandas-datareader/issues/977
""")


@utils.memoize
def yf(ticker: str, field, start=None, end=None, mrefresh=False) -> Union[pd.Series, pd.DataFrame]:
if field is None:
field = "Adj Close"

yfinance.pdr_override()

tmp = pdata.get_data_yahoo(ticker, start=start, end=end)
tmp = yfinance.download(ticker, start=start, end=end)

if tmp is None:
raise ValueError("failed to retrieve data for %s:%s" % (ticker, field))
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies = [
"matplotlib>=1",
"numpy",
"pandas>=0.19",
"pandas-datareader>=0.2",
"scikit-learn>=0.15",
"scipy>=0.15",
"tabulate>=0.7.5",
Expand Down Expand Up @@ -72,4 +71,3 @@ line-length = 180

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403"]

0 comments on commit 174a0cd

Please sign in to comment.