Skip to content
New issue

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

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

Already on GitHub? # to your account

issue38 Resolve numpy deprecation warnings #39

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

MitchellAcoustics
Copy link
Collaborator

tests/test__signal.py: 319 warnings
  /Users/mitch/Documents/GitHub/acoustic-toolbox/.venv/lib/python3.12/site-packages/scipy/signal/_filter_design.py:3001: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    bw = float(bw)

happens when we do frequencies.lower on a single frequency/OctaveBand value (e.g. frequencies[0].lower or bands.lower). Since Frequencies applies np.asarray(lower) by default, we end up with np.array([<float>]). Whereas if frequencies.lower[0] was used, it would be fine, since that would extract a single float value from the array.

From v2, `__array_wrap__` needs `return_scalar` argument. Implemented with a check for numpy version for backwards compatibility to numpy v1.
Looks like this will also be deprecated in the future, so this is a bit of a hack, but it will all change if we change to `xarray` anyway.
```
tests/test__signal.py: 319 warnings
  /Users/mitch/Documents/GitHub/acoustic-toolbox/.venv/lib/python3.12/site-packages/scipy/signal/_filter_design.py:3001: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    bw = float(bw)
```

happens when we do `frequencies.lower` on a single frequency/OctaveBand value (e.g. `frequencies[0].lower` or `bands.lower`). Since `Frequencies` applies `np.asarray(lower)` by default, we end up with `np.array([<float>])`. Whereas if `frequencies.lower[0]` was used, it would be fine, since that would extract a single float value from the array.
@MitchellAcoustics MitchellAcoustics changed the title MitchellAcoustics/issue38 #38 Resolve numpy deprecation warnings Feb 19, 2025
@MitchellAcoustics MitchellAcoustics changed the title #38 Resolve numpy deprecation warnings issue38 Resolve numpy deprecation warnings Feb 19, 2025
@MitchellAcoustics MitchellAcoustics self-assigned this Feb 19, 2025
@MitchellAcoustics MitchellAcoustics added the bug Something isn't working label Feb 19, 2025
@MitchellAcoustics
Copy link
Collaborator Author

Closes #38 by resolving numpy deprecation warnings related to Signal.__array_wrap__(). Also addresses a deprecation warning where a numpy ndarray with only a single value used to be coerced to scalar - numpy deprecated this so we handle it explicitly in the frequency bands.

mkdocs-jupyter or pandoc seem unhappy about the mkdocstrings include section having an unclosed div `:::`. See danielfrg/mkdocs-jupyter#231 (comment)
@MitchellAcoustics MitchellAcoustics merged commit f5bae25 into main Feb 19, 2025
2 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant