8000 Fix some incorrect ValueErrors. · sullis/matplotlib@950a31b · GitHub
[go: up one dir, main page]

Skip to content

Commit 950a31b

Browse files
committed
Fix some incorrect ValueErrors.
... which should have read ValueError(string % args) instead of ValueError(string, args). But we may as well use check_getitem and f-strings now.
1 parent 0ea2013 commit 950a31b

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7284,27 +7284,24 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
72847284
if Fc is None:
72857285
Fc = 0
72867286

7287-
if scale is None or scale == 'default':
7288-
scale = 'linear'
7289-
72907287
spec, freqs = mlab.magnitude_spectrum(x=x, Fs=Fs, window=window,
72917288
pad_to=pad_to, sides=sides)
72927289
freqs += Fc
72937290

7294-
if scale == 'linear':
7291+
yunits = cbook._check_getitem(
7292+
{None: 'energy', 'default': 'energy', 'linear': 'energy',
7293+
'dB': 'dB'},
7294+
scale=scale)
7295+
if yunits == 'energy':
72957296
Z = spec
7296-
yunits = 'energy'
7297-
elif scale == 'dB':
7297+
else: # yunits == 'dB'
72987298
Z = 20. * np.log10(spec)
7299-
yunits = 'dB'
7300-
else:
7301-
raise ValueError('Unknown scale %s', scale)
73027299

7303-
lines = self.plot(freqs, Z, **kwargs)
7300+
line, = self.plot(freqs, Z, **kwargs)
73047301
self.set_xlabel('Frequency')
73057302
self.set_ylabel('Magnitude (%s)' % yunits)
73067303

7307-
return spec, freqs, lines[0]
7304+
return spec, freqs, line
73087305

73097306
@_preprocess_data(replace_names=["x"])
73107307
@docstring.dedent_interpd

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def _post_post(self, _):
483483

484484
@_dispatch(min=250, max=255)
485485
def _malformed(self, offset):
486-
raise ValueError("unknown command: byte %d", 250 + offset)
486+
raise ValueError(f"unknown command: byte {250 + offset}")
487487

488488

489489
class DviFont:

0 commit comments

Comments
 (0)
0