From 158b789631580051ba3449bc964003e8b8b26910 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Mon, 20 Nov 2023 11:45:08 +0800 Subject: [PATCH 1/4] STY: Be more selective with checks used This commit avoids the `--select ALL` antipattern. This is an anti-pattern as, using `ALL` changes the checks run whenever any of the underlying styles are updated. --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 82df604..db109eb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -48,4 +48,4 @@ jobs: # Tell us what version we are using poetry run ruff version # Check the source file, ignore type annotations (ANN) for now. - poetry run ruff check numpy_financial/ --ignore F403,Q000,PLR0913,ERA001,TRY003,EM101,EM102,RET505,D203,D213,ANN --select ALL + poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I From 0c4c8745bf45033190b558ba4637aa6cc15d8700 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Mon, 20 Nov 2023 11:47:06 +0800 Subject: [PATCH 2/4] STY: Sort imports --- tests/test_financial.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_financial.py b/tests/test_financial.py index d6986de..37a5d6e 100644 --- a/tests/test_financial.py +++ b/tests/test_financial.py @@ -1,13 +1,17 @@ -from decimal import Decimal import math +from decimal import Decimal # Don't use 'import numpy as np', to avoid accidentally testing # the versions in numpy instead of numpy_financial. import numpy +import pytest from numpy.testing import ( - assert_, assert_almost_equal, assert_allclose, assert_equal, assert_raises + assert_, + assert_allclose, + assert_almost_equal, + assert_equal, + assert_raises, ) -import pytest import numpy_financial as npf From fc40b0ea6f2ba8575de3618f25359e040d957a73 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Mon, 20 Nov 2023 11:52:21 +0800 Subject: [PATCH 3/4] STY: Fix line too long errors from style check --- tests/test_financial.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_financial.py b/tests/test_financial.py index 37a5d6e..ad01952 100644 --- a/tests/test_financial.py +++ b/tests/test_financial.py @@ -257,7 +257,9 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected): @pytest.mark.parametrize( "args, expected", [ - ({'values': ['-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000'], + ({'values': [ + '-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000' + ], 'finance_rate': '0.08', 'reinvest_rate': '0.055' }, '0.066597175031553548874239618' ), @@ -277,7 +279,11 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected): ) def test_mirr_decimal(self, number_type, args, expected): values = [number_type(v) for v in args['values']] - result = npf.mirr(values, number_type(args['finance_rate']), number_type(args['reinvest_rate'])) + result = npf.mirr( + values, + number_type(args['finance_rate']), + number_type(args['reinvest_rate']) + ) if expected is not numpy.nan: assert_almost_equal(result, number_type(expected), 15) @@ -289,7 +295,9 @@ def test_mirr_no_real_solution_exception(self): # have the same sign, then npf.mirr returns NoRealSolutionException # when raise_exceptions is set to True. val = [39000, 30000, 21000, 37000, 46000] - assert_raises(npf.NoRealSolutionError, npf.mirr, val, 0.10, 0.12, raise_exceptions=True) + + with pytest.raises(npf.NoRealSolutionError): + npf.mirr(val, 0.10, 0.12, raise_exceptions=True) class TestNper: @@ -721,12 +729,15 @@ def test_irr_no_real_solution_exception(self): # have the same sign, then npf.irr returns NoRealSolutionException # when raise_exceptions is set to True. cashflows = numpy.array([40000, 5000, 8000, 12000, 30000]) - assert_raises(npf.NoRealSolutionError, npf.irr, cashflows, raise_exceptions=True) + + with pytest.raises(npf.NoRealSolutionError): + npf.irr(cashflows, raise_exceptions=True) def test_irr_maximum_iterations_exception(self): # Test that if the maximum number of iterations is reached, # then npf.irr returns IterationsExceededException # when raise_exceptions is set to True. cashflows = numpy.array([-40000, 5000, 8000, 12000, 30000]) - assert_raises(npf.IterationsExceededError, npf.irr, cashflows, - maxiter=1, raise_exceptions=True) + + with pytest.raises(npf.IterationsExceededError): + npf.irr(cashflows, maxiter=1, raise_exceptions=True) From 0e9fb51c399acc0db4a97e90cd4a46d9eff46886 Mon Sep 17 00:00:00 2001 From: Kai Striega Date: Mon, 20 Nov 2023 11:53:35 +0800 Subject: [PATCH 4/4] STY/CI: Add ruff check for tests/ directory --- .github/workflows/lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index db109eb..47f1db9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,3 +49,5 @@ jobs: poetry run ruff version # Check the source file, ignore type annotations (ANN) for now. poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I + # Check the test file + poetry run ruff check tests/ --select E,F,B,I