summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorjakobjakobson13 <43045863+jakobjakobson13@users.noreply.github.com>2020-10-25 19:47:15 +0100
committerGitHub <noreply@github.com>2020-10-25 12:47:15 -0600
commitca39060bd4f98657139f782ff9c02a1f095ed3dc (patch)
tree487f306c73bf8cbb92f921f36e1a581fa3d4cce9 /numpy/ma
parent1245f9da021d65789a3332f0e046ca30d518e9c8 (diff)
downloadnumpy-ca39060bd4f98657139f782ff9c02a1f095ed3dc.tar.gz
MAINT: Conversion of some strings to fstrings, part III (#17623)
* Conversion of some strings to fstrings * Remove spaces * Update numpy/ma/mrecords.py Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> * Update numpy/ma/tests/test_old_ma.py Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> * Update numpy/ma/timer_comparison.py Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> Co-authored-by: Jakob <jakobjakobson13@posteo.de> Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/bench.py10
-rw-r--r--numpy/ma/mrecords.py16
-rw-r--r--numpy/ma/tests/test_core.py24
-rw-r--r--numpy/ma/tests/test_old_ma.py2
-rw-r--r--numpy/ma/tests/test_subclassing.py8
-rw-r--r--numpy/ma/testutils.py10
-rw-r--r--numpy/ma/timer_comparison.py5
7 files changed, 37 insertions, 38 deletions
diff --git a/numpy/ma/bench.py b/numpy/ma/bench.py
index 83cc6aea7..e29d54365 100644
--- a/numpy/ma/bench.py
+++ b/numpy/ma/bench.py
@@ -58,7 +58,7 @@ def compare_functions_1v(func, nloop=500,
xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl):
funcname = func.__name__
print("-"*50)
- print("%s on small arrays" % funcname)
+ print(f'{funcname} on small arrays')
module, data = "numpy.ma", "nmxs"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
@@ -70,8 +70,8 @@ def compare_functions_1v(func, nloop=500,
def compare_methods(methodname, args, vars='x', nloop=500, test=True,
xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl):
print("-"*50)
- print("%s on small arrays" % methodname)
- data, ver = "nm%ss" % vars, 'numpy.ma'
+ print(f'{methodname} on small arrays')
+ data, ver = f'nm{vars}l', 'numpy.ma'
timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop)
print("%s on large arrays" % methodname)
@@ -86,11 +86,11 @@ def compare_functions_2v(func, nloop=500, test=True,
yl=yl, nmyl=nmyl):
funcname = func.__name__
print("-"*50)
- print("%s on small arrays" % funcname)
+ print(f'{funcname} on small arrays')
module, data = "numpy.ma", "nmxs,nmys"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
- print("%s on large arrays" % funcname)
+ print(f'{funcname} on large arrays')
module, data = "numpy.ma", "nmxl,nmyl"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
return
diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py
index c017bee95..70087632e 100644
--- a/numpy/ma/mrecords.py
+++ b/numpy/ma/mrecords.py
@@ -60,7 +60,7 @@ def _checknames(descr, names=None):
elif isinstance(names, str):
new_names = names.split(',')
else:
- raise NameError("illegal input names %s" % repr(names))
+ raise NameError(f'illegal input names {names!r}')
nnames = len(new_names)
if nnames < ndescr:
new_names += default_names[nnames:]
@@ -199,7 +199,7 @@ class MaskedRecords(MaskedArray):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError) as e:
- raise AttributeError("record array has no attribute %s" % attr) from e
+ raise AttributeError(f'record array has no attribute {attr}') from e
# So far, so good
_localdict = ndarray.__getattribute__(self, '__dict__')
_data = ndarray.view(self, _localdict['_baseclass'])
@@ -274,7 +274,7 @@ class MaskedRecords(MaskedArray):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError):
- raise AttributeError("record array has no attribute %s" % attr)
+ raise AttributeError(f'record array has no attribute {attr}')
if val is masked:
_fill_value = _localdict['_fill_value']
@@ -337,13 +337,13 @@ class MaskedRecords(MaskedArray):
"""
if self.size > 1:
- mstr = ["(%s)" % ",".join([str(i) for i in s])
+ mstr = [f"({','.join([str(i) for i in s])})"
for s in zip(*[getattr(self, f) for f in self.dtype.names])]
- return "[%s]" % ", ".join(mstr)
+ return f"[{', '.join(mstr)}]"
else:
- mstr = ["%s" % ",".join([str(i) for i in s])
+ mstr = [f"{','.join([str(i) for i in s])}"
for s in zip([getattr(self, f) for f in self.dtype.names])]
- return "(%s)" % ", ".join(mstr)
+ return f"({', '.join(mstr)})"
def __repr__(self):
"""
@@ -657,7 +657,7 @@ def openfile(fname):
try:
f = open(fname)
except IOError:
- raise IOError("No such file: '%s'" % fname)
+ raise IOError(f"No such file: '{fname}'")
if f.readline()[:2] != "\\x":
f.seek(0, 0)
return f
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 0ed2971e6..6a2ed8ca7 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -2748,7 +2748,7 @@ class TestMaskedArrayInPlaceArithmetics:
xm += t(1)
assert_equal(xm, y + t(1))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_addition_array_type(self):
# Test of inplace additions
@@ -2765,7 +2765,7 @@ class TestMaskedArrayInPlaceArithmetics:
assert_equal(xm, y + a)
assert_equal(xm.mask, mask_or(m, a.mask))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_subtraction_scalar_type(self):
# Test of inplace subtractions
@@ -2778,7 +2778,7 @@ class TestMaskedArrayInPlaceArithmetics:
xm -= t(1)
assert_equal(xm, y - t(1))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_subtraction_array_type(self):
# Test of inplace subtractions
@@ -2795,7 +2795,7 @@ class TestMaskedArrayInPlaceArithmetics:
assert_equal(xm, y - a)
assert_equal(xm.mask, mask_or(m, a.mask))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_multiplication_scalar_type(self):
# Test of inplace multiplication
@@ -2808,7 +2808,7 @@ class TestMaskedArrayInPlaceArithmetics:
xm *= t(2)
assert_equal(xm, y * t(2))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_multiplication_array_type(self):
# Test of inplace multiplication
@@ -2825,7 +2825,7 @@ class TestMaskedArrayInPlaceArithmetics:
assert_equal(xm, y * a)
assert_equal(xm.mask, mask_or(m, a.mask))
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_floor_division_scalar_type(self):
# Test of inplace division
@@ -2861,7 +2861,7 @@ class TestMaskedArrayInPlaceArithmetics:
mask_or(mask_or(m, a.mask), (a == t(0)))
)
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
def test_inplace_division_scalar_type(self):
# Test of inplace division
@@ -2895,9 +2895,9 @@ class TestMaskedArrayInPlaceArithmetics:
warnings.warn(str(e), stacklevel=1)
if issubclass(t, np.integer):
- assert_equal(len(sup.log), 2, "Failed on type=%s." % t)
+ assert_equal(len(sup.log), 2, f'Failed on type={t}.')
else:
- assert_equal(len(sup.log), 0, "Failed on type=%s." % t)
+ assert_equal(len(sup.log), 0, f'Failed on type={t}.')
def test_inplace_division_array_type(self):
# Test of inplace division
@@ -2934,9 +2934,9 @@ class TestMaskedArrayInPlaceArithmetics:
warnings.warn(str(e), stacklevel=1)
if issubclass(t, np.integer):
- assert_equal(len(sup.log), 2, "Failed on type=%s." % t)
+ assert_equal(len(sup.log), 2, f'Failed on type={t}.')
else:
- assert_equal(len(sup.log), 0, "Failed on type=%s." % t)
+ assert_equal(len(sup.log), 0, f'Failed on type={t}.')
def test_inplace_pow_type(self):
# Test keeping data w/ (inplace) power
@@ -2954,7 +2954,7 @@ class TestMaskedArrayInPlaceArithmetics:
assert_equal(x.data, xx_r.data)
assert_equal(x.mask, xx_r.mask)
- assert_equal(len(w), 0, "Failed on type=%s." % t)
+ assert_equal(len(w), 0, f'Failed on type={t}.')
class TestMaskedArrayMethods:
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index 96c7e3609..ab003b94e 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -27,7 +27,7 @@ pi = np.pi
def eq(v, w, msg=''):
result = allclose(v, w)
if not result:
- print("Not eq:%s\n%s\n----%s" % (msg, str(v), str(w)))
+ print(f'Not eq:{msg}\n{v}\n----{w}')
return result
diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py
index caa746740..f2623406d 100644
--- a/numpy/ma/tests/test_subclassing.py
+++ b/numpy/ma/tests/test_subclassing.py
@@ -109,11 +109,11 @@ class CSAIterator:
class ComplicatedSubArray(SubArray):
def __str__(self):
- return 'myprefix {0} mypostfix'.format(self.view(SubArray))
+ return f'myprefix {self.view(SubArray)} mypostfix'
def __repr__(self):
# Return a repr that does not start with 'name('
- return '<{0} {1}>'.format(self.__class__.__name__, self)
+ return f'<{self.__class__.__name__} {self}>'
def _validate_input(self, value):
if not isinstance(value, ComplicatedSubArray):
@@ -317,8 +317,8 @@ class TestSubclassing:
assert_startswith(repr(mx), 'masked_array')
xsub = SubArray(x)
mxsub = masked_array(xsub, mask=[True, False, True, False, False])
- assert_startswith(repr(mxsub),
- 'masked_{0}(data=[--, 1, --, 3, 4]'.format(SubArray.__name__))
+ assert_startswith(repr(mxsub),
+ f'masked_{SubArray.__name__}(data=[--, 1, --, 3, 4]')
def test_subclass_str(self):
"""test str with subclass that has overridden str, setitem"""
diff --git a/numpy/ma/testutils.py b/numpy/ma/testutils.py
index 51ab03948..8d55e1763 100644
--- a/numpy/ma/testutils.py
+++ b/numpy/ma/testutils.py
@@ -86,7 +86,7 @@ def _assert_equal_on_sequences(actual, desired, err_msg=''):
"""
assert_equal(len(actual), len(desired), err_msg)
for k in range(len(desired)):
- assert_equal(actual[k], desired[k], 'item=%r\n%s' % (k, err_msg))
+ assert_equal(actual[k], desired[k], f'item={k!r}\n{err_msg}')
return
@@ -117,8 +117,8 @@ def assert_equal(actual, desired, err_msg=''):
assert_equal(len(actual), len(desired), err_msg)
for k, i in desired.items():
if k not in actual:
- raise AssertionError("%s not in %s" % (k, actual))
- assert_equal(actual[k], desired[k], 'key=%r\n%s' % (k, err_msg))
+ raise AssertionError(f"{k} not in {actual}")
+ assert_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')
return
# Case #2: lists .....
if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):
@@ -156,12 +156,12 @@ def fail_if_equal(actual, desired, err_msg='',):
for k, i in desired.items():
if k not in actual:
raise AssertionError(repr(k))
- fail_if_equal(actual[k], desired[k], 'key=%r\n%s' % (k, err_msg))
+ fail_if_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')
return
if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):
fail_if_equal(len(actual), len(desired), err_msg)
for k in range(len(desired)):
- fail_if_equal(actual[k], desired[k], 'item=%r\n%s' % (k, err_msg))
+ fail_if_equal(actual[k], desired[k], f'item={k!r}\n{err_msg}')
return
if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):
return fail_if_array_equal(actual, desired, err_msg)
diff --git a/numpy/ma/timer_comparison.py b/numpy/ma/timer_comparison.py
index f5855efcf..aff72f79b 100644
--- a/numpy/ma/timer_comparison.py
+++ b/numpy/ma/timer_comparison.py
@@ -77,8 +77,7 @@ class ModuleTester:
if not cond:
msg = build_err_msg([x, y],
err_msg
- + '\n(shapes %s, %s mismatch)' % (x.shape,
- y.shape),
+ + f'\n(shapes {x.shape}, {y.shape} mismatch)',
header=header,
names=('x', 'y'))
assert cond, msg
@@ -434,4 +433,4 @@ if __name__ == '__main__':
cur = np.sort(cur)
print("#%i" % i + 50*'.')
print(eval("ModuleTester.test_%i.__doc__" % i))
- print("core_current : %.3f - %.3f" % (cur[0], cur[1]))
+ print(f'core_current : {cur[0]:.3f} - {cur[1]:.3f}')