Skip to content

Commit

Permalink
Merge pull request #1830 from ange-daumal/patch-1
Browse files Browse the repository at this point in the history
Fix JSON error handling
  • Loading branch information
ValueRaider authored Jan 19, 2024
2 parents 73e3668 + 91f468e commit 7af789f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
from .const import _BASE_URL_, _ROOT_URL_, price_colnames


_empty_series = pd.Series()


class TickerBase:
def __init__(self, ticker, session=None, proxy=None):
self.ticker = ticker.upper()
Expand Down Expand Up @@ -1962,7 +1965,7 @@ def get_capital_gains(self, proxy=None) -> pd.Series:
if self._history is not None and "Capital Gains" in self._history:
capital_gains = self._history["Capital Gains"]
return capital_gains[capital_gains != 0]
return pd.Series()
return _empty_series

def get_splits(self, proxy=None) -> pd.Series:
if self._history is None:
Expand All @@ -1972,7 +1975,7 @@ def get_splits(self, proxy=None) -> pd.Series:
return splits[splits != 0]
return pd.Series()

def get_actions(self, proxy=None) -> pd.DataFrame:
def get_actions(self, proxy=None) -> pd.Series:
if self._history is None:
self.history(period="max", proxy=proxy)
if self._history is not None and "Dividends" in self._history and "Stock Splits" in self._history:
Expand All @@ -1981,7 +1984,7 @@ def get_actions(self, proxy=None) -> pd.DataFrame:
action_columns.append("Capital Gains")
actions = self._history[action_columns]
return actions[actions != 0].dropna(how='all').fillna(0)
return pd.DataFrame()
return _empty_series

def get_shares(self, proxy=None, as_dict=False) -> Union[pd.DataFrame, dict]:
self._fundamentals.proxy = proxy or self.proxy
Expand Down

0 comments on commit 7af789f

Please sign in to comment.