Skip to content

Commit c26860f

Browse files
committed
MAINT: small cleanups for fv
- Remove an unused variable in the implementation - Adjust some spacing in the implementation - Use the ternary operator in tests to make them read better
1 parent 8c7e6e1 commit c26860f

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

numpy_financial/_financial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ def fv(rate, nper, pmt, pv, when='end'):
133133
fv_array[zero] = -(pv[zero] + pmt[zero] * nper[zero])
134134

135135
rate_nonzero = rate[nonzero]
136-
nper_nonzero = nper[nonzero]
137136
temp = (1 + rate_nonzero)**nper[nonzero]
138137
fv_array[nonzero] = (
139-
-pv[nonzero] * temp
138+
- pv[nonzero] * temp
140139
- pmt[nonzero] * (1 + rate_nonzero * when[nonzero]) / rate_nonzero
141140
* (temp - 1)
142141
)

numpy_financial/tests/test_financial.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,7 @@ def test_when_is_begin_decimal(self, when):
482482
@pytest.mark.parametrize('when', [None, 0, 'end'])
483483
def test_when_is_end_float(self, when):
484484
args = (0.075, 20, -2000, 0)
485-
if when is None:
486-
result = npf.fv(*args)
487-
else:
488-
result = npf.fv(*args, when)
485+
result = npf.fv(*args) if when is None else npf.fv(*args, when)
489486
assert_allclose(
490487
result,
491488
86609.362673, # Computed using Google Sheet's FV
@@ -500,10 +497,7 @@ def test_when_is_end_decimal(self, when):
500497
Decimal('-2000'),
501498
Decimal('0'),
502499
)
503-
if when is None:
504-
result = npf.fv(*args)
505-
else:
506-
result = npf.fv(*args, when)
500+
result = npf.fv(*args) if when is None else npf.fv(*args, when)
507501
assert_almost_equal(result, Decimal('86609.362673'), decimal=5)
508502

509503
def test_broadcast(self):

0 commit comments

Comments
 (0)