Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
fixes #171, fixes #170
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Dec 17, 2020
1 parent 62483ea commit 7b54e15
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
2 changes: 2 additions & 0 deletions pyEX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@
financialsDF,
fundOwnership,
fundOwnershipDF,
fundamentals,
fundamentalsDF,
incomeStatement,
incomeStatementDF,
insiderRoster,
Expand Down
4 changes: 4 additions & 0 deletions pyEX/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@
financialsDF,
fundOwnership,
fundOwnershipDF,
fundamentals,
fundamentalsDF,
incomeStatement,
incomeStatementDF,
insiderRoster,
Expand Down Expand Up @@ -915,6 +917,8 @@
("financialsDF", financialsDF),
("fundOwnership", fundOwnership),
("fundOwnershipDF", fundOwnershipDF),
("fundamentals", fundamentals),
("fundamentalsDF", fundamentalsDF),
("incomeStatement", incomeStatement),
("incomeStatementDF", incomeStatementDF),
("insiderRoster", insiderRoster),
Expand Down
2 changes: 2 additions & 0 deletions pyEX/stocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
earningsDF,
financials,
financialsDF,
fundamentals,
fundamentalsDF,
incomeStatement,
incomeStatementDF,
stockSplits,
Expand Down
28 changes: 12 additions & 16 deletions pyEX/stocks/fundamentals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
_toDatetime,
_checkPeriodLast,
_UTC,
json_normalize,
)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyEX/stocks/profiles.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions pyEX/tests/test_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7b54e15

Please sign in to comment.