Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b68335d

Browse files
committed
Fix mlab fallback for 32-bit systems
Unfortunately, I applied the change from matplotlib#29115 (comment) directly without noticing the typo, or running full tests. So fix the swapped condition, and add a test (for `csd` only, which should be enough since everything goes though `_spectral_helper`.)
1 parent e7a09ac commit b68335d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

‎lib/matplotlib/mlab.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ def _stride_windows(x, n, noverlap=0):
215215
x = np.asarray(x)
216216

217217
_api.check_isinstance(Integral, n=n, noverlap=noverlap)
218-
if not (1 <= n <= x.size and n < noverlap):
219-
raise ValueError(f'n ({n}) and noverlap ({noverlap}) must be positive integers '
220-
f'with n < noverlap and n <= x.size ({x.size})')
221-
222-
if n == 1 and noverlap == 0:
223-
return x[np.newaxis]
218+
if not (0 <= noverlap < n <= x.size):
219+
raise ValueError(
220+
f'n ({n}), noverlap ({noverlap}), and x.size ({x.size}) must satisfy '
221+
f'0 <= noverlap < n <= x.size')
224222

225223
step = n - noverlap
226224
shape = (n, (x.shape[-1]-noverlap)//step)
@@ -257,7 +255,7 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
257255
if NFFT is None:
258256
NFFT = 256
259257

260-
if noverlap>=NFFT:
258+
if not (0<=noverlap<NFFT):
261259
raise ValueError('noverlap must be less than NFFT')
262260

263261
if mode is None or mode == 'default':

‎lib/matplotlib/tests/test_mlab.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from numpy.testing import (assert_allclose, assert_almost_equal,
24
assert_array_equal, assert_array_almost_equal_nulp)
35
import numpy as np
@@ -429,7 +431,16 @@ def test_spectral_helper_psd(self, mode, case):
429431
assert spec.shape[0] == freqs.shape[0]
430432
assert spec.shape[1] == getattr(self, f"t_{case}").shape[0]
431433

432-
def test_csd(self):
434+
@pytest.mark.parametrize('bitsize', [
435+
pytest.param(None, id='default'),
436+
pytest.param(32,
437+
marks=pytest.mark.skipif(sys.maxsize <= 2**32,
438+
reason='System is already 32-bit'),
439+
id='32-bit')
440+
])
441+
def test_csd(self, bitsize, monkeypatch):
442+
if bitsize is not None:
443+
monkeypatch.setattr(sys, 'maxsize', 2**bitsize)
433444
freqs = self.freqs_density
434445
spec, fsp = mlab.csd(x=self.y, y=self.y+1,
435446
NFFT=self.NFFT_density,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /