From 7b54e150f016088eb16beefc54816112905f4d12 Mon Sep 17 00:00:00 2001 From: Tim Paine Date: Wed, 16 Dec 2020 22:34:02 -0500 Subject: [PATCH] fixes #171, fixes #170 --- pyEX/__init__.py | 2 ++ pyEX/client.py | 4 ++++ pyEX/stocks/__init__.py | 2 ++ pyEX/stocks/fundamentals.py | 28 ++++++++++++---------------- pyEX/stocks/profiles.py | 3 +++ pyEX/tests/test_stocks.py | 16 ++++++++++++---- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/pyEX/__init__.py b/pyEX/__init__.py index 62afebb..da298bf 100644 --- a/pyEX/__init__.py +++ b/pyEX/__init__.py @@ -373,6 +373,8 @@ financialsDF, fundOwnership, fundOwnershipDF, + fundamentals, + fundamentalsDF, incomeStatement, incomeStatementDF, insiderRoster, diff --git a/pyEX/client.py b/pyEX/client.py index d8bb028..68c72ae 100644 --- a/pyEX/client.py +++ b/pyEX/client.py @@ -353,6 +353,8 @@ financialsDF, fundOwnership, fundOwnershipDF, + fundamentals, + fundamentalsDF, incomeStatement, incomeStatementDF, insiderRoster, @@ -915,6 +917,8 @@ ("financialsDF", financialsDF), ("fundOwnership", fundOwnership), ("fundOwnershipDF", fundOwnershipDF), + ("fundamentals", fundamentals), + ("fundamentalsDF", fundamentalsDF), ("incomeStatement", incomeStatement), ("incomeStatementDF", incomeStatementDF), ("insiderRoster", insiderRoster), diff --git a/pyEX/stocks/__init__.py b/pyEX/stocks/__init__.py index e4779fc..9984cf7 100644 --- a/pyEX/stocks/__init__.py +++ b/pyEX/stocks/__init__.py @@ -39,6 +39,8 @@ earningsDF, financials, financialsDF, + fundamentals, + fundamentalsDF, incomeStatement, incomeStatementDF, stockSplits, diff --git a/pyEX/stocks/fundamentals.py b/pyEX/stocks/fundamentals.py index f68fb56..b7ff509 100644 --- a/pyEX/stocks/fundamentals.py +++ b/pyEX/stocks/fundamentals.py @@ -12,7 +12,6 @@ _toDatetime, _checkPeriodLast, _UTC, - json_normalize, ) @@ -42,13 +41,12 @@ def balanceSheet(symbol, period="quarter", last=1, token="", version="", filter= token, version, filter, - ) + ).get("balancesheet", []) @wraps(balanceSheet) def balanceSheetDF(symbol, period="quarter", last=1, token="", version="", filter=""): - val = balanceSheet(symbol, period, last, token, version, filter) - df = json_normalize(val, "balancesheet", "symbol") + df = pd.DataFrame(balanceSheet(symbol, period, last, token, version, filter)) _toDatetime(df) _reindex(df, "reportDate") return df @@ -80,13 +78,12 @@ def cashFlow(symbol, period="quarter", last=1, token="", version="", filter=""): token, version, filter, - ) + ).get("cashflow", []) @wraps(cashFlow) def cashFlowDF(symbol, period="quarter", last=1, token="", version="", filter=""): - val = cashFlow(symbol, period, last, token, version, filter) - df = json_normalize(val, "cashflow", "symbol") + df = pd.DataFrame(cashFlow(symbol, period, last, token, version, filter)) _toDatetime(df) _reindex(df, "reportDate") df.replace(to_replace=[None], value=np.nan, inplace=True) @@ -166,13 +163,13 @@ def earnings( token, version, filter, - ) + ).get("earnings", []) def _earningsToDF(e): """internal""" if e: - df = json_normalize(e, "earnings", "symbol") + df = pd.DataFrame(e) _toDatetime(df) _reindex(df, "EPSReportDate") else: @@ -210,13 +207,13 @@ def financials(symbol, period="quarter", token="", version="", filter=""): _checkPeriodLast(period, 1) return _getJson( "stock/{}/financials?period={}".format(symbol, period), token, version, filter - ) + ).get("financials", []) def _financialsToDF(f): """internal""" if f: - df = json_normalize(f, "financials", "symbol") + df = pd.DataFrame(f) _toDatetime(df) _reindex(df, "reportDate") else: @@ -252,13 +249,13 @@ def fundamentals(symbol, period="quarter", token="", version="", filter=""): _checkPeriodLast(period, 1) return _getJson( "stock/{}/fundamentals?period={}".format(symbol, period), token, version, filter - ) + ).get("fundamentals", []) def _fundamentalsToDF(f): """internal""" if f: - df = pd.io.json.json_normalize(f, "fundamentals", "symbol") + df = pd.DataFrame(f) _toDatetime(df) _reindex(df, "reportDate") else: @@ -298,15 +295,14 @@ def incomeStatement(symbol, period="quarter", last=1, token="", version="", filt token, version, filter, - ) + ).get("income", []) @wraps(incomeStatement) def incomeStatementDF( symbol, period="quarter", last=1, token="", version="", filter="" ): - val = incomeStatement(symbol, period, last, token, version, filter) - df = json_normalize(val, "income", "symbol") + df = pd.DataFrame(incomeStatement(symbol, period, last, token, version, filter)) _toDatetime(df) _reindex(df, "reportDate") return df diff --git a/pyEX/stocks/profiles.py b/pyEX/stocks/profiles.py index dfa0a54..ce95107 100644 --- a/pyEX/stocks/profiles.py +++ b/pyEX/stocks/profiles.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import requests import pandas as pd +from deprecation import deprecated from functools import wraps from IPython.display import Image as ImageI from io import BytesIO @@ -234,6 +235,7 @@ def peersDF(symbol, token="", version="", filter=""): @_expire(hour=8, tz=_UTC) +@deprecated(details="Deprecated: IEX Cloud status unkown") def relevant(symbol, token="", version="", filter=""): """Same as peers @@ -252,6 +254,7 @@ def relevant(symbol, token="", version="", filter=""): @wraps(relevant) +@deprecated(details="Deprecated: IEX Cloud status unkown") def relevantDF(symbol, token="", version="", filter=""): df = pd.DataFrame(relevant(symbol, token, version, filter)) _toDatetime(df) diff --git a/pyEX/tests/test_stocks.py b/pyEX/tests/test_stocks.py index 9b0da39..6538a3d 100644 --- a/pyEX/tests/test_stocks.py +++ b/pyEX/tests/test_stocks.py @@ -267,7 +267,7 @@ def test_financialsDF(self): mock.return_value = MagicMock() mock.return_value.status_code = 200 mock.return_value.json = MagicMock( - return_value=[{"financials": [{"reportDate": 1}], "symbol": "aapl"}] + return_value={"financials": [{"reportDate": 1, "b": 2}], "symbol": "aapl"} ) financialsDF("test") @@ -695,7 +695,9 @@ def test_balancesheetDF(self): with patch("requests.get") as mock, patch("pickle.dump"): mock.return_value = MagicMock() mock.return_value.status_code = 200 - mock.return_value.json = MagicMock(return_value=[]) + mock.return_value.json = MagicMock( + return_value={"balancesheet": [{"reportDate": 1, "b": 2}], "symbol": "aapl"} + ) c = Client(version="sandbox") c.balanceSheetDF(SYMBOL) @@ -714,7 +716,10 @@ def test_cashflowDF(self): with patch("requests.get") as mock, patch("pickle.dump"): mock.return_value = MagicMock() mock.return_value.status_code = 200 - mock.return_value.json = MagicMock(return_value=[]) + mock.return_value.json = MagicMock( + return_value={"cashflow": [{"reportDate": 1, "b": 2}], "symbol": "aapl"} + ) + c = Client(version="sandbox") c.cashFlowDF(SYMBOL) @@ -733,7 +738,10 @@ def test_incomeDF(self): with patch("requests.get") as mock, patch("pickle.dump"): mock.return_value = MagicMock() mock.return_value.status_code = 200 - mock.return_value.json = MagicMock(return_value=[]) + mock.return_value.json = MagicMock( + return_value={"income": [{"reportDate": 1, "b": 2}], "symbol": "aapl"} + ) + c = Client(version="sandbox") c.incomeStatementDF(SYMBOL)