From d3a4b90bde5838659c2c24613ac84f2a035fd637 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 14:57:46 +0100 Subject: [PATCH 01/14] GitHub Action to lint Python code --- .github/workflows/lint_python.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/lint_python.yml diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 00000000000..0fba0e0678c --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,19 @@ +name: lint_python +on: [pull_request, push] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade + - run: bandit -r . || true + - run: black --check . || true + - run: codespell --quiet-level=2 || true # --ignore-words-list="" --skip="" + - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - run: isort --check-only --profile black . || true + - run: pip install -r requirements.txt || true + - run: mypy --ignore-missing-imports . || true + - run: pytest . || true + - run: pytest --doctest-modules . || true + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true From d7e613fc78b76f95c326f15cb89109d6b0fb9e67 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 15:00:28 +0100 Subject: [PATCH 02/14] Use ==/!= to compare constant literals (str, bytes, int, float, tuple) --- prediction_techniques/neural_networks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prediction_techniques/neural_networks.py b/prediction_techniques/neural_networks.py index ff1c24f6fa7..1929843ad23 100644 --- a/prediction_techniques/neural_networks.py +++ b/prediction_techniques/neural_networks.py @@ -27,7 +27,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): for idx_layer, d_layer in enumerate(Recurrent_Neural_Network): # Recurrent Neural Network - if str(*d_layer) is 'SimpleRNN': + if str(*d_layer) == 'SimpleRNN': # Is this the input layer? If so, define input_shape if idx_layer == 0: model.add(SimpleRNN(**d_layer['SimpleRNN'], input_shape=(n_inputs, 1))) @@ -38,7 +38,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): model.add(SimpleRNN(**d_layer['SimpleRNN'])) # Long-Short Term-Memory - elif str(*d_layer) is 'LSTM': + elif str(*d_layer) == 'LSTM': # Is this the input layer? If so, define input_shape if idx_layer == 0: model.add(LSTM(**d_layer['LSTM'], input_shape=(n_inputs, 1))) @@ -49,7 +49,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): model.add(LSTM(**d_layer['LSTM'])) # Dense (Simple Neuron) - elif str(*d_layer) is 'Dense': + elif str(*d_layer) == 'Dense': # Is this the input layer? If so, define input_shape if idx_layer == 0: model.add(Dense(**d_layer['Dense'], input_dim=n_inputs)) From 39f0ae4b85b333b3ac82b73570eaf8e3a027f5d6 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 15:02:15 +0100 Subject: [PATCH 03/14] Use ==/!= to compare constant literals (str, bytes, int, float, tuple) --- discovery/short_interest_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discovery/short_interest_api.py b/discovery/short_interest_api.py index 901fc555723..351eec49bb4 100644 --- a/discovery/short_interest_api.py +++ b/discovery/short_interest_api.py @@ -43,7 +43,7 @@ def high_short_interest(l_args): l_stock_info = list() for elem in a_high_short_interested_stocks: - if elem is '': + if elem == '': continue l_stock_info.append(elem) @@ -92,7 +92,7 @@ def low_float(l_args): l_stock_info = list() for elem in a_low_float_stocks: - if elem is '': + if elem == '': continue l_stock_info.append(elem) @@ -103,4 +103,4 @@ def low_float(l_args): pd.set_option('display.max_colwidth', -1) print(df_low_float.head(n=ns_parser.n_num).to_string(index=False)) - print("") \ No newline at end of file + print("") From 6e1914fe893431a53c292e12d11f93b34a20a6e7 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 15:07:38 +0100 Subject: [PATCH 04/14] Update neural_networks.py --- prediction_techniques/neural_networks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prediction_techniques/neural_networks.py b/prediction_techniques/neural_networks.py index 1929843ad23..38f7da13f85 100644 --- a/prediction_techniques/neural_networks.py +++ b/prediction_techniques/neural_networks.py @@ -60,7 +60,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): model.add(Dense(**d_layer['Dense'])) # Dropout (Regularization) - elif str(*d_layer) is 'Dropout': + elif str(*d_layer) == 'Dropout': model.add(Dropout(**d_layer['Dropout'])) else: From 0b7b354300f942174b312e3a836936dc99465bd7 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 15:16:22 +0100 Subject: [PATCH 05/14] Update lint_python.yml --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 0fba0e0678c..7f810f4f6c5 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -12,7 +12,7 @@ jobs: - run: codespell --quiet-level=2 || true # --ignore-words-list="" --skip="" - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt || true + - run: pip install -r requirements.txt - run: mypy --ignore-missing-imports . || true - run: pytest . || true - run: pytest --doctest-modules . || true From 79106c5efeace97e96523159e6082f41bd1578cf Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:19:13 +0100 Subject: [PATCH 06/14] codespell --ignore-words-list="mape" --quiet-level=2 --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 7f810f4f6c5..1354fefee97 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -9,7 +9,7 @@ jobs: - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade - run: bandit -r . || true - run: black --check . || true - - run: codespell --quiet-level=2 || true # --ignore-words-list="" --skip="" + - run: codespell --ignore-words-list="mape" --quiet-level=2 || true # --skip="" - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - run: pip install -r requirements.txt From 58ae580aa53ca66f3153c429ff38c849c0fed34e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:22:02 +0100 Subject: [PATCH 07/14] Fix typos discovered by codespell --- sentiment/reddit_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sentiment/reddit_api.py b/sentiment/reddit_api.py index 6ef651a33ec..61132119b40 100644 --- a/sentiment/reddit_api.py +++ b/sentiment/reddit_api.py @@ -104,7 +104,7 @@ def watchlist(l_args): d_watchlist_tickers[key] = 1 l_watchlist_links.append(f"https://www.reddit.com{submission.permalink}") - # delte below, not necessary I reckon. Probably just link? + # delete below, not necessary I reckon. Probably just link? # Refactor data s_datetime = datetime.utcfromtimestamp(submission.created_utc).strftime("%d/%m/%Y %H:%M:%S") @@ -361,7 +361,7 @@ def spac_community(l_args): d_watchlist_tickers[key] = 1 l_watchlist_links.append(f"https://www.reddit.com{submission.permalink}") - # delte below, not necessary I reckon. Probably just link? + # delete below, not necessary I reckon. Probably just link? # Refactor data s_datetime = datetime.utcfromtimestamp(submission.created_utc).strftime("%d/%m/%Y %H:%M:%S") @@ -497,7 +497,7 @@ def spac(l_args): d_watchlist_tickers[key] = 1 l_watchlist_links.append(f"https://www.reddit.com{submission.permalink}") - # delte below, not necessary I reckon. Probably just link? + # delete below, not necessary I reckon. Probably just link? # Refactor data s_datetime = datetime.utcfromtimestamp(submission.created_utc).strftime("%d/%m/%Y %H:%M:%S") @@ -642,4 +642,4 @@ def wsb_community(l_args): break print("") except: - print("") \ No newline at end of file + print("") From b1ab52c34f6cd1dff506fb0cc985f7216acd11d9 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:24:09 +0100 Subject: [PATCH 08/14] Fix typos discovered by codespell --- fundamental_analysis/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fundamental_analysis/README.md b/fundamental_analysis/README.md index 2501ab3ad88..f5cdc6046e7 100644 --- a/fundamental_analysis/README.md +++ b/fundamental_analysis/README.md @@ -178,7 +178,7 @@ Prints a complete balance sheet statement over time. This can be either quarterl ``` usage: cash [-n N_NUM] [-q] ``` -Prints a complete cash flow statement over time. This can be either quarterly or annually. The following fields are expected: Accepted date, Accounts payables, Accounts receivables, Acquisitions net, Capital expenditure, Cash at beginning of period, Cash at end of period, Change in working capital, Common stock issued, Common stock repurchased, Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, Net cash used for investing activites, Net cash used provided by financing activities, Net change in cash, Net income, Operating cash flow, Other financing activites, Other investing activites, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Alpha Vantage] +Prints a complete cash flow statement over time. This can be either quarterly or annually. The following fields are expected: Accepted date, Accounts payables, Accounts receivables, Acquisitions net, Capital expenditure, Cash at beginning of period, Cash at end of period, Change in working capital, Common stock issued, Common stock repurchased, Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, Net cash used for investing activities, Net cash used provided by financing activities, Net change in cash, Net income, Operating cash flow, Other financing activities, Other investing activities, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Alpha Vantage] * n : Number of latest years/quarters. Default 1. * q : Quarter fundamental data flag. Default False. @@ -241,7 +241,7 @@ Prints a complete balance sheet statement over time. This can be either quarterl ``` usage: cashf [-n N_NUM] [-q] ``` -Prints a complete cash flow statement over time. This can be either quarterly or annually. The following fields are expected: Accepted date, Accounts payables, Accounts receivables, Acquisitions net, Capital expenditure, Cash at beginning of period, Cash at end of period, Change in working capital, Common stock issued, Common stock repurchased, Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, Net cash used for investing activites, Net cash used provided by financing activities, Net change in cash, Net income, Operating cash flow, Other financing activites, Other investing activites, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Financial Modeling Prep] +Prints a complete cash flow statement over time. This can be either quarterly or annually. The following fields are expected: Accepted date, Accounts payables, Accounts receivables, Acquisitions net, Capital expenditure, Cash at beginning of period, Cash at end of period, Change in working capital, Common stock issued, Common stock repurchased, Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, Net cash used for investing activities, Net cash used provided by financing activities, Net change in cash, Net income, Operating cash flow, Other financing activities, Other investing activities, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Financial Modeling Prep] * n : Number of latest years/quarters. Default 1. * q : Quarter fundamental data flag. Default False. From a2a3945a49f9489b390cdf97dda34e06b6254b1a Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:26:41 +0100 Subject: [PATCH 09/14] Fix typos discovered by codespell --- fundamental_analysis/alpha_vantage_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fundamental_analysis/alpha_vantage_api.py b/fundamental_analysis/alpha_vantage_api.py index 87a9b1288f8..8de17800192 100644 --- a/fundamental_analysis/alpha_vantage_api.py +++ b/fundamental_analysis/alpha_vantage_api.py @@ -247,9 +247,9 @@ def cash_flow(l_args, s_ticker): Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, - Net cash used for investing activites, Net cash used provided by financing activities, Net - change in cash, Net income, Operating cash flow, Other financing activites, Other investing - activites, Other non cash items, Other working capital, Period, Purchases of investments, + Net cash used for investing activities, Net cash used provided by financing activities, Net + change in cash, Net income, Operating cash flow, Other financing activities, Other investing + activities, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Alpha Vantage]""") parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=1, @@ -329,7 +329,7 @@ def earnings(l_args, s_ticker): "estimatedEPS":"Estimated EPS", "reportedDate":"Reported Date", "surprise":"Surprise", - "surprisePercentage":"Suprise Percentage"}) + "surprisePercentage":"Surprise Percentage"}) else: df_fa = pd.DataFrame(df_fa['annualEarnings'][0]) df_fa = df_fa.rename(columns={"fiscalDateEnding":"Fiscal Date Ending", From a4846aaaf44db87a9e492f126904b43d2612425f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:27:47 +0100 Subject: [PATCH 10/14] Fix typos discovered by codespell --- fundamental_analysis/financial_modeling_prep_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fundamental_analysis/financial_modeling_prep_api.py b/fundamental_analysis/financial_modeling_prep_api.py index f9e9e684296..7ff1558b585 100644 --- a/fundamental_analysis/financial_modeling_prep_api.py +++ b/fundamental_analysis/financial_modeling_prep_api.py @@ -286,9 +286,9 @@ def cash_flow(l_args, s_ticker): Debt repayment, Deferred income tax, Depreciation and amortization, Dividends paid, Effect of forex changes on cash, Filling date, Final link, Free cash flow, Inventory, Investments in property plant and equipment, Link, Net cash provided by operating activities, - Net cash used for investing activites, Net cash used provided by financing activities, Net - change in cash, Net income, Operating cash flow, Other financing activites, Other investing - activites, Other non cash items, Other working capital, Period, Purchases of investments, + Net cash used for investing activities, Net cash used provided by financing activities, Net + change in cash, Net income, Operating cash flow, Other financing activities, Other investing + activities, Other non cash items, Other working capital, Period, Purchases of investments, Sales maturities of investments, Stock based compensation. [Source: Financial Modeling Prep]""") parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=1, @@ -509,4 +509,4 @@ def financial_statement_growth(l_args, s_ticker): except: print("") return - \ No newline at end of file + From 7089673ded8728403a4b2eec3fa68e621ecb6a3b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:28:49 +0100 Subject: [PATCH 11/14] Make codespell a mandatory test --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 1354fefee97..318f5a74e0e 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -9,7 +9,7 @@ jobs: - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade - run: bandit -r . || true - run: black --check . || true - - run: codespell --ignore-words-list="mape" --quiet-level=2 || true # --skip="" + - run: codespell --ignore-words-list="mape" --quiet-level=2 # --skip="" - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - run: pip install -r requirements.txt From 794467443c3f9a22b2c8445619ad34aa64df907b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Feb 2021 21:37:43 +0100 Subject: [PATCH 12/14] pip install -r requirements.txt || true --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 318f5a74e0e..5d7ca7652a3 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -12,7 +12,7 @@ jobs: - run: codespell --ignore-words-list="mape" --quiet-level=2 # --skip="" - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt + - run: pip install -r requirements.txt || true - run: mypy --ignore-missing-imports . || true - run: pytest . || true - run: pytest --doctest-modules . || true From 9e79817bd51ecc43c50c44d4888c0e3b96d29cd3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 28 Feb 2021 08:09:18 +0100 Subject: [PATCH 13/14] Update lint_python.yml --- .github/workflows/lint_python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 5d7ca7652a3..e72ec894a9b 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -6,7 +6,7 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade + - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade safety - run: bandit -r . || true - run: black --check . || true - run: codespell --ignore-words-list="mape" --quiet-level=2 # --skip="" @@ -17,3 +17,4 @@ jobs: - run: pytest . || true - run: pytest --doctest-modules . || true - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true + - run: safety check || true From 9b0d92b89ca32abef0e4b467843ee1b98c0e71f0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 28 Feb 2021 08:12:04 +0100 Subject: [PATCH 14/14] Make safety check a mandatory test --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index e72ec894a9b..3365e5f3f6b 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -17,4 +17,4 @@ jobs: - run: pytest . || true - run: pytest --doctest-modules . || true - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true - - run: safety check || true + - run: safety check