diff options
| author | Mike Taves <mwtoews@gmail.com> | 2021-08-30 11:01:34 +1200 |
|---|---|---|
| committer | Mike Taves <mwtoews@gmail.com> | 2021-09-01 21:50:59 +1200 |
| commit | 64f15a94708095bf9d29af5dbfcc4b654a57248a (patch) | |
| tree | 77bd3bf8a4f38561fee95fcfa3ea9e5247e6500b /numpy/core | |
| parent | 5ae53e93b2be9ccf47bf72a85d71ea15d15a2eed (diff) | |
| download | numpy-64f15a94708095bf9d29af5dbfcc4b654a57248a.tar.gz | |
MAINT: refactor "for ... in range(len(" statements
Diffstat (limited to 'numpy/core')
| -rw-r--r-- | numpy/core/records.py | 12 | ||||
| -rw-r--r-- | numpy/core/tests/test_umath_complex.py | 16 |
2 files changed, 13 insertions, 15 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index b3474ad01..2c20b7d45 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -664,17 +664,17 @@ def fromarrays(arrayList, dtype=None, shape=None, formats=None, if nn > 0: shape = shape[:-nn] + _array = recarray(shape, descr) + + # populate the record array (makes a copy) for k, obj in enumerate(arrayList): nn = descr[k].ndim testshape = obj.shape[:obj.ndim - nn] + name = _names[k] if testshape != shape: - raise ValueError("array-shape mismatch in array %d" % k) + raise ValueError(f'array-shape mismatch in array {k} ("{name}")') - _array = recarray(shape, descr) - - # populate the record array (makes a copy) - for i in range(len(arrayList)): - _array[_names[i]] = arrayList[i] + _array[name] = obj return _array diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py index ad09830d4..af5bbe59e 100644 --- a/numpy/core/tests/test_umath_complex.py +++ b/numpy/core/tests/test_umath_complex.py @@ -134,8 +134,7 @@ class TestClog: x = np.array([1+0j, 1+2j]) y_r = np.log(np.abs(x)) + 1j * np.angle(x) y = np.log(x) - for i in range(len(x)): - assert_almost_equal(y[i], y_r[i]) + assert_almost_equal(y, y_r) @platform_skip @pytest.mark.skipif(platform.machine() == "armv5tel", reason="See gh-413.") @@ -365,8 +364,7 @@ class TestCpow: x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan]) y_r = x ** 2 y = np.power(x, 2) - for i in range(len(x)): - assert_almost_equal(y[i], y_r[i]) + assert_almost_equal(y, y_r) def test_scalar(self): x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan]) @@ -419,8 +417,7 @@ class TestCabs: x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan]) y_r = np.array([np.sqrt(2.), 2, np.sqrt(5), np.inf, np.nan]) y = np.abs(x) - for i in range(len(x)): - assert_almost_equal(y[i], y_r[i]) + assert_almost_equal(y, y_r) def test_fabs(self): # Test that np.abs(x +- 0j) == np.abs(x) (as mandated by C99 for cabs) @@ -466,9 +463,10 @@ class TestCabs: return np.abs(complex(a, b)) xa = np.array(x, dtype=complex) - for i in range(len(xa)): - ref = g(x[i], y[i]) - check_real_value(f, x[i], y[i], ref) + assert len(xa) == len(x) == len(y) + for xi, yi in zip(x, y): + ref = g(xi, yi) + check_real_value(f, xi, yi, ref) class TestCarg: def test_simple(self): |
