Skip to content

Commit

Permalink
updated tests/, tqdm removed & release setup
Browse files Browse the repository at this point in the history
tests updated to improve code coverage when retrieving data from intervals over 20 years

removed return statements that are lines missed because previous checks avoid them

tqdm package removed as it is not necessary and it can also be annoying (even though it can be useful when testing functions)

setup.py, requirements.txtm README.md and .travis.yml updated to fit new release version 0.8.4.8

additionally notebooks/ have been removed as improves, proposals and changes tests need to be done in another repo or branch so as no to interfere in investpy package
  • Loading branch information
alvarob96 committed May 29, 2019
1 parent a092919 commit 9369c2f
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 18,710 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ __pycache__/
.tox
.cache
.pytest_cache
*.pyc
*.pyc
.DS_Store
475 changes: 309 additions & 166 deletions .idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ install:
- pip install pandas==0.24.2
- pip install requests==2.22.0
- pip install lxml==4.3.3
- pip install unidecode==1.0.23
- pip install tqdm==4.32.1
- pip install investpy==0.8.4.7
- pip install Unidecode==1.0.23
- pip install investpy==0.8.4.8
- pip install pytest==4.5.0
- pip install codecov==2.0.15
- pip install pytest-cov==2.7.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To conclude this section, I am in the need to specify that this is not the final

In order to get this package working you will need to install [**investpy**](https://pypi.org/project/investpy/) from PyPi via Terminal typing:

``pip install investpy==0.8.4.7``
``pip install investpy==0.8.4.8``

All the dependencies are already listed on the setup file of the package, but to sum them up, you will need the following requirements:

Expand Down
52 changes: 14 additions & 38 deletions investpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import datetime
import json
from random import randint
from tqdm import tqdm

import pandas as pd
import pkg_resources
Expand Down Expand Up @@ -77,8 +76,7 @@ def get_recent_data(equity, as_json=False, order='ascending'):
if pkg_resources.resource_exists(resource_package, resource_path):
equities = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = ts.get_equity_names()
equities = pd.DataFrame(names)
equities = pd.DataFrame(ts.get_equity_names())

if equities is None:
raise IOError("ERR#001: equities object not found or unable to retrieve.")
Expand Down Expand Up @@ -108,7 +106,7 @@ def get_recent_data(equity, as_json=False, order='ascending'):
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -234,8 +232,7 @@ def get_historical_data(equity, start, end, as_json=False, order='ascending'):
if pkg_resources.resource_exists(resource_package, resource_path):
equities = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = ts.get_equity_names()
equities = pd.DataFrame(names)
equities = pd.DataFrame(ts.get_equity_names())

if equities is None:
raise IOError("ERR#001: equities object not found or unable to retrieve.")
Expand Down Expand Up @@ -299,7 +296,7 @@ def get_historical_data(equity, start, end, as_json=False, order='ascending'):
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -350,11 +347,6 @@ def get_historical_data(equity, start, end, as_json=False, order='ascending'):
else:
continue

if as_json is True:
return {}
elif as_json is False:
return pd.DataFrame()


def get_equity_company_profile(equity, language='english'):
"""
Expand Down Expand Up @@ -392,8 +384,7 @@ def get_equity_company_profile(equity, language='english'):
if pkg_resources.resource_exists(resource_package, resource_path):
equities = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = ts.get_equity_names()
equities = pd.DataFrame(names)
equities = pd.DataFrame(ts.get_equity_names())

if equities is None:
raise IOError("ERR#001: equities object not found or unable to retrieve.")
Expand Down Expand Up @@ -537,8 +528,7 @@ def get_fund_recent_data(fund, as_json=False, order='ascending'):
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = fs.get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(fs.get_fund_names())

if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")
Expand Down Expand Up @@ -568,7 +558,7 @@ def get_fund_recent_data(fund, as_json=False, order='ascending'):
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -686,8 +676,7 @@ def get_fund_historical_data(fund, start, end, as_json=False, order='ascending')
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = fs.get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(fs.get_fund_names())

if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")
Expand Down Expand Up @@ -734,7 +723,7 @@ def get_fund_historical_data(fund, start, end, as_json=False, order='ascending')
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -777,11 +766,6 @@ def get_fund_historical_data(fund, start, end, as_json=False, order='ascending')
else:
continue

if as_json is True:
return {}
elif as_json is False:
return pd.DataFrame()


def get_fund_information(fund, as_json=False):
"""
Expand All @@ -808,8 +792,7 @@ def get_fund_information(fund, as_json=False):
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = fs.get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(fs.get_fund_names())

if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")
Expand Down Expand Up @@ -989,8 +972,7 @@ def get_etf_recent_data(etf, as_json=False, order='ascending'):
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = es.get_etf_names()
etfs = pd.DataFrame(names)
etfs = pd.DataFrame(es.get_etf_names())

if etfs is None:
raise IOError("ERR#009: etfs object not found or unable to retrieve.")
Expand Down Expand Up @@ -1020,7 +1002,7 @@ def get_etf_recent_data(etf, as_json=False, order='ascending'):
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -1138,8 +1120,7 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = es.get_etf_names()
etfs = pd.DataFrame(names)
etfs = pd.DataFrame(es.get_etf_names())

if etfs is None:
raise IOError("ERR#009: etfs object not found or unable to retrieve.")
Expand Down Expand Up @@ -1186,7 +1167,7 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
result = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
info = []
for nested_ in elements_.xpath(".//td"):
info.append(nested_.text_content())
Expand Down Expand Up @@ -1228,8 +1209,3 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
return pd.concat(final)
else:
continue

if as_json is True:
return {}
elif as_json is False:
return pd.DataFrame()
9 changes: 3 additions & 6 deletions investpy/equities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pkg_resources
import requests
from lxml.html import fromstring
from tqdm import tqdm

from investpy import user_agent as ua

Expand Down Expand Up @@ -57,7 +56,7 @@ def get_equity_names():
results = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
id_ = elements_.get('id').replace('pair_', '')

for element_ in elements_.xpath('.//a'):
Expand Down Expand Up @@ -153,8 +152,7 @@ def get_equities():
if pkg_resources.resource_exists(resource_package, resource_path):
equities = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_equity_names()
equities = pd.DataFrame(names)
equities = pd.DataFrame(get_equity_names())

if equities is None:
raise IOError("ERR#001: equities list not found or unable to retrieve.")
Expand All @@ -177,8 +175,7 @@ def list_equities():
if pkg_resources.resource_exists(resource_package, resource_path):
equities = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_equity_names()
equities = pd.DataFrame(names)
equities = pd.DataFrame(get_equity_names())

if equities is None:
raise IOError("ERR#001: equities list not found or unable to retrieve.")
Expand Down
12 changes: 4 additions & 8 deletions investpy/etfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pkg_resources
import requests
from lxml.html import fromstring
from tqdm import tqdm

from investpy import user_agent as ua

Expand Down Expand Up @@ -49,7 +48,7 @@ def get_etf_names():
results = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
id_ = elements_.get('id').replace('pair_', '')
symbol = elements_.xpath(".//td[contains(@class, 'symbol')]")[0].get('title')

Expand Down Expand Up @@ -98,8 +97,7 @@ def get_etfs():
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_etf_names()
etfs = pd.DataFrame(names)
etfs = pd.DataFrame(get_etf_names())

if etfs is None:
raise IOError("ERR#009: etf list not found or unable to retrieve.")
Expand All @@ -122,8 +120,7 @@ def list_etfs():
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_etf_names()
etfs = pd.DataFrame(names)
etfs = pd.DataFrame(get_etf_names())

if etfs is None:
raise IOError("ERR#009: etf list not found or unable to retrieve.")
Expand Down Expand Up @@ -156,8 +153,7 @@ def dict_etfs(columns=None, as_json=False):
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_etf_names()
etfs = pd.DataFrame(names)
etfs = pd.DataFrame(get_etf_names())

if etfs is None:
raise IOError("ERR#009: etf list not found or unable to retrieve.")
Expand Down
12 changes: 4 additions & 8 deletions investpy/funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pkg_resources
import requests
from lxml.html import fromstring
from tqdm import tqdm

from investpy import user_agent as ua

Expand Down Expand Up @@ -49,7 +48,7 @@ def get_fund_names():
results = list()

if path_:
for elements_ in tqdm(path_, ascii=True, ncols=80):
for elements_ in path_:
id_ = elements_.get('id').replace('pair_', '')
symbol = elements_.xpath(".//td[contains(@class, 'symbol')]")[0].get('title')

Expand Down Expand Up @@ -210,8 +209,7 @@ def get_funds():
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(get_fund_names())

if funds is None:
raise IOError("ERR#005: fund list not found or unable to retrieve.")
Expand All @@ -234,8 +232,7 @@ def list_funds():
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(get_fund_names())

if funds is None:
raise IOError("ERR#005: fund list not found or unable to retrieve.")
Expand Down Expand Up @@ -268,8 +265,7 @@ def dict_funds(columns=None, as_json=False):
if pkg_resources.resource_exists(resource_package, resource_path):
funds = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_fund_names()
funds = pd.DataFrame(names)
funds = pd.DataFrame(get_fund_names())

if funds is None:
raise IOError("ERR#005: fund list not found or unable to retrieve.")
Expand Down
Loading

0 comments on commit 9369c2f

Please sign in to comment.