From 1c9a9e99b0ba58c623cb4131d3ef0e266172d6e8 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sun, 13 Apr 2025 17:54:15 +0200 Subject: [PATCH 1/5] MAINT: bump `ruff` to `0.11.5` --- environment.yml | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/environment.yml b/environment.yml index ea9c15f..0c21dac 100644 --- a/environment.yml +++ b/environment.yml @@ -26,8 +26,8 @@ dependencies: - numpydoc - pydata-sphinx-theme>=0.15.0 # Lint - - ruff>=0.3.0 + - ruff>=0.11.5 # Benchmarks - asv>=0.6.0 # Misc tools - - ipython \ No newline at end of file + - ipython diff --git a/pyproject.toml b/pyproject.toml index a08f689..8741869 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ doc = [ "myst-parser>=2.0.0", ] dev = [ - "ruff>=0.3.0", + "ruff>=0.11.5", "asv>=0.6.0", ] From 5b533be4f8b30ca1f3c4fdb04454f3e92ead1402 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sun, 13 Apr 2025 17:56:43 +0200 Subject: [PATCH 2/5] STY: Fix `ruff/B905` --- numpy_financial/_financial.py | 24 +++++++++++++----------- numpy_financial/tests/test_financial.py | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index da019e2..fc84a5e 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -756,7 +756,7 @@ def irr(values, *, raise_exceptions=False, selection_logic=_irr_default_selectio User may insert their own customised function for selection of IRR values.The function should accept a one-dimensional array of numbers and return a number. - + Returns ------- @@ -803,7 +803,7 @@ def irr(values, *, raise_exceptions=False, selection_logic=_irr_default_selectio 0.0886 >>> npf.irr([[-100, 0, 0, 74], [-100, 100, 0, 7]]).round(5) array([-0.0955 , 0.06206]) - + """ values = np.atleast_2d(values) if values.ndim != 2: @@ -852,7 +852,7 @@ def irr(values, *, raise_exceptions=False, selection_logic=_irr_default_selectio # If only one real solution elif len(eirr) == 1: irr_results[i] = eirr[0] - else: + else: irr_results[i] = selection_logic(eirr) return _ufunc_like(irr_results) @@ -986,7 +986,7 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): .. math:: - MIRR = + MIRR = \\left( \\frac{{FV_{positive}}}{{PV_{negative}}} \\right)^{\\frac{{1}}{{n-1}}} * (1+r) - 1 @@ -1000,8 +1000,8 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): -------- >>> import numpy_financial as npf - Consider a project with an initial investment of -$100 - and projected cash flows of $50, -$60, and $70 at the end of each period. + Consider a project with an initial investment of -$100 + and projected cash flows of $50, -$60, and $70 at the end of each period. The project has a finance rate of 10% and a reinvestment rate of 12%. >>> npf.mirr([-100, 50, -60, 70], 0.10, 0.12) @@ -1028,17 +1028,17 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): >>> npf.mirr([-100, -50, -60, -70], 0.10, 0.12) nan - Finally, let's explore the situation where all cash flows are positive, + Finally, let's explore the situation where all cash flows are positive, and the `raise_exceptions` parameter is set to True. >>> npf.mirr([ - ... 100, 50, 60, 70], - ... 0.10, 0.12, + ... 100, 50, 60, 70], + ... 0.10, 0.12, ... raise_exceptions=True ... ) #doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... - numpy_financial._financial.NoRealSolutionError: + numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. """ values_inner = np.atleast_2d(values).astype(np.float64) @@ -1055,7 +1055,9 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): out = np.empty(out_shape) for i, v in enumerate(values_inner): - for j, (rr, fr) in enumerate(zip(reinvest_rate_inner, finance_rate_inner)): + for j, (rr, fr) in enumerate( + zip(reinvest_rate_inner, finance_rate_inner, strict=False) + ): pos = v > 0 neg = v < 0 diff --git a/numpy_financial/tests/test_financial.py b/numpy_financial/tests/test_financial.py index 7b95f3d..2b8ea76 100644 --- a/numpy_financial/tests/test_financial.py +++ b/numpy_financial/tests/test_financial.py @@ -26,7 +26,7 @@ def assert_decimal_close(actual, expected, tol=Decimal("1e-7")): # Check if both actual and expected are iterable (like arrays) if hasattr(actual, "__iter__") and hasattr(expected, "__iter__"): - for a, e in zip(actual, expected): + for a, e in zip(actual, expected, strict=False): assert abs(a - e) <= tol else: # For single value comparisons From 96f9e7016077470635b94d678885e0467099ff56 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sun, 13 Apr 2025 18:10:01 +0200 Subject: [PATCH 3/5] TST: Fix (flaky?) test on Windows --- numpy_financial/tests/test_financial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_financial/tests/test_financial.py b/numpy_financial/tests/test_financial.py index 2b8ea76..7a80abf 100644 --- a/numpy_financial/tests/test_financial.py +++ b/numpy_financial/tests/test_financial.py @@ -760,7 +760,7 @@ def test_npv_irr_congruence(self): assert_allclose( npf.npv(npf.irr(cashflows), cashflows), 0, - atol=1e-10, + atol=1e-9, rtol=0, ) From a4de21bb9253f13dcc34e039ef4e520d7823575c Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 17 Apr 2025 01:25:59 +0200 Subject: [PATCH 4/5] TST: use ``strict=True`` in the ``zip`` of ``assert_decimal_close`` Co-authored-by: kai-striega --- numpy_financial/tests/test_financial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_financial/tests/test_financial.py b/numpy_financial/tests/test_financial.py index 7a80abf..765e1b2 100644 --- a/numpy_financial/tests/test_financial.py +++ b/numpy_financial/tests/test_financial.py @@ -26,7 +26,7 @@ def assert_decimal_close(actual, expected, tol=Decimal("1e-7")): # Check if both actual and expected are iterable (like arrays) if hasattr(actual, "__iter__") and hasattr(expected, "__iter__"): - for a, e in zip(actual, expected, strict=False): + for a, e in zip(actual, expected, strict=True): assert abs(a - e) <= tol else: # For single value comparisons From dab283b54d6707c8bb596d7092daf142649d92bc Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 17 Apr 2025 01:28:56 +0200 Subject: [PATCH 5/5] STY: use ``strict=True`` in the ``zip`` of ``mirr`` Co-authored-by: kai-striega --- numpy_financial/_financial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index fc84a5e..3b6bbe1 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -1056,7 +1056,7 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): for i, v in enumerate(values_inner): for j, (rr, fr) in enumerate( - zip(reinvest_rate_inner, finance_rate_inner, strict=False) + zip(reinvest_rate_inner, finance_rate_inner, strict=True) ): pos = v > 0 neg = v < 0