From 2f1174dee44e901b7d028beb86f4a8ea324bd74f Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Thu, 11 Jul 2013 16:49:04 -0600 Subject: MAINT: Use np.errstate context manager. Now that Python < 2.6 is no longer supported we can use the errstate context manager in places where constructs like ``` old = seterr(invalid='ignore') try: blah finally: seterr(**old) ``` were used. --- numpy/lib/financial.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'numpy/lib/financial.py') diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index 0be12f2c7..8cac117c9 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -266,14 +266,11 @@ def nper(rate, pmt, pv, fv=0, when='end'): (rate, pmt, pv, fv, when) = map(np.asarray, [rate, pmt, pv, fv, when]) use_zero_rate = False - old_err = np.seterr(divide="raise") - try: + with np.errstate(divide="raise"): try: z = pmt*(1.0+rate*when)/rate except FloatingPointError: use_zero_rate = True - finally: - np.seterr(**old_err) if use_zero_rate: return (-fv + pv) / (pmt + 0.0) -- cgit v1.2.1