8000 BUG: signal.csd: doesn't zero-pad for different size inputs in 1.16.0rc1 · Issue #23036 · scipy/scipy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

BUG: signal.csd: doesn't zero-pad for different size inputs in 1.16.0rc1 #23036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
duncanmmacleod opened this issue May 22, 2025 · 2 comments · Fixed by #23047
Closed

BUG: signal.csd: doesn't zero-pad for different size inputs in 1.16.0rc1 #23036

duncanmmacleod opened this issue May 22, 2025 · 2 comments · Fixed by #23047
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal
Milestone

Comments

@duncanmmacleod
Copy link

Describe your issue.

The scipy.signal.csd function in 1.16.0rc1 advertises the following (as it has done forever):

If the input series differ in length, the shorter series will be
zero-padded to match.

However, it seems like since #22460 the zero-padding isn't actually applied, and an error is raised because the ShortTimeFFT attempts to access a slice that it thinks it can't get to. Error details below.

P.S. I would be very happy to be told this is user error and it never should have worked. Thanks for supporting scipy, it's great.

Reproducing Code Example

import numpy.random
import scipy.signal
rng = numpy.random.default_rng(0)
a = rng.random(1024)
b = rng.random(2048)
scipy.signal.csd(a, b, fs=128, nperseg=128)

Error message

Traceback (most recent call last):
  File "/home/duncan/git/gitlab.com/gwpy/gwpy/worktrees/scipy-1.16/test.py", line 6, in <module>
    scipy.signal.csd(a, b, fs=128, nperseg=128)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/duncan/opt/conda/envs/test/lib/python3.13/site-packages/scipy/signal/_spectral_py.py", line 908, in csd
    Pxy = SFT.spectrogram(y, x, detr=None if detrend is False else detrend,
                          p0=0, p1=(n - noverlap) // SFT.hop, k_offset=nperseg // 2,
                          axis=axis)
  File "/home/duncan/opt/conda/envs/test/lib/python3.13/site-packages/scipy/signal/_short_time_fft.py", line 1387, in spectrogram
    Sy = self.stft_detrend(y, detr, p0, p1, k_offset=k_offset,
                           padding=padding, axis=axis)
  File "/home/duncan/opt/conda/envs/test/lib/python3.13/site-packages/scipy/signal/_short_time_fft.py", line 1234, in stft_detrend
    p0, p1 = self.p_range(n, p0, p1)
             ~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/duncan/opt/conda/envs/test/lib/python3.13/site-packages/scipy/signal/_short_time_fft.py", line 1910, in p_range
    raise ValueError(f"Invalid Parameter {p0=}, {p1=}, i.e., " +
                     f"{self.p_min=} <= p0 < p1 <= {p_max=} " +
                     f"does not hold for signal length {n=}!")
ValueError: Invalid Parameter p0=0, p1=31, i.e., self.p_min=0 <= p0 < p1 <= p_max=17 does not hold for signal length n=1024!

SciPy/NumPy/Python version and system information

1.16.0rc1 2.2.5 sys.version_info(major=3, minor=13, micro=3, releaselevel='final', serial=0)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /opt/_internal/cpython-3.13.2/lib/python3.13/site-packages/scipy_openblas32/include
    lib directory: /opt/_internal/cpython-3.13.2/lib/python3.13/site-packages/scipy_openblas32/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.28 DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=64
    pc file directory: /project
    version: 0.3.28
  lapack:
    detection method: pkgconfig
    found: true
    include directory: /opt/_internal/cpython-3.13.2/lib/python3.13/site-packages/scipy_openblas32/include
    lib directory: /opt/_internal/cpython-3.13.2/lib/python3.13/site-packages/scipy_openblas32/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.28 DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=64
    pc file directory: /project
    version: 0.3.28
  pybind11:
    detection method: config-tool
    include directory: unknown
    name: pybind11
    version: 2.13.6
Compilers:
  c:
    commands: cc
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  c++:
    commands: c++
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.1.1
  fortran:
    commands: gfortran
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  pythran:
    include directory: ../../tmp/pip-build-env-81uwjfeo/overlay/lib/python3.13/site-packages/pythran
    version: 0.17.0
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
  cross-compiled: false
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
Python Information:
  path: /opt/python/cp313-cp313/bin/python
  version: '3.13'
@duncanmmacleod duncanmmacleod added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label May 22, 2025
@j-bowhay j-bowhay added this to the 1.16.0 milestone May 22, 2025
@j-bowhay
Copy link
Member

cc @DietBru

DietBru added a commit to DietBru/scipy that referenced this issue May 23, 2025
Fixes scipy#23036

This bug was introduced in 1.16.0rc1 with PR scipy#22460.
@DietBru
Copy link
Contributor
DietBru commented May 23, 2025

Thanks @duncanmmacleod for taking the time to test the prerelease!

P.S. I would be very happy to be told this is user error and it never should have worked. Thanks for supporting scipy, it's great.

I do not think it is a user error since it broke previously working code. Fixed in #23047.

@lucascolley lucascolley changed the title BUG: scipy.signal.csd doesn't zero-pad for different size inputs in 1.16.0rc1 BUG: signal.csd: doesn't zero-pad for different size inputs in 1.16.0rc1 Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0