forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scipy#12558 from peterbell10/scipy-fft-function
MAINT: Remove hack to allow scipy.fft to act like a function
- Loading branch information
Showing
4 changed files
with
46 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
import numpy as np | ||
import subprocess | ||
import sys | ||
|
||
TEST_BODY = r""" | ||
import pytest | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
import scipy | ||
import sys | ||
import pytest | ||
if hasattr(scipy, 'fft'): | ||
raise AssertionError("scipy.fft should require an explicit import") | ||
np.random.seed(1234) | ||
x = np.random.randn(10) + 1j * np.random.randn(10) | ||
X = np.fft.fft(x) | ||
# Callable before scipy.fft is imported | ||
with pytest.deprecated_call(match=r'2\.0\.0'): | ||
y = scipy.ifft(X) | ||
assert_allclose(y, x) | ||
# Callable after scipy.fft is imported | ||
import scipy.fft | ||
with pytest.deprecated_call(match=r'2\.0\.0'): | ||
y = scipy.ifft(X) | ||
assert_allclose(y, x) | ||
""" | ||
|
||
def test_fft_function(): | ||
# Many NumPy symbols are imported into the scipy namespace, including | ||
# numpy.fft.fft as scipy.fft, conflicting with this module (gh-10253) | ||
np.random.seed(1234) | ||
|
||
# Callable before scipy.fft is imported | ||
import scipy | ||
x = np.random.randn(10) + 1j * np.random.randn(10) | ||
with pytest.deprecated_call(match=r'1\.5\.0'): | ||
X = scipy.fft(x) | ||
with pytest.deprecated_call(match=r'2\.0\.0'): | ||
y = scipy.ifft(X) | ||
assert_allclose(y, x) | ||
|
||
# Callable after scipy.fft is imported | ||
import scipy.fft | ||
assert_allclose(X, scipy.fft.fft(x)) | ||
with pytest.deprecated_call(match=r'1\.5\.0'): | ||
X = scipy.fft(x) | ||
assert_allclose(X, scipy.fft.fft(x)) | ||
with pytest.deprecated_call(match=r'2\.0\.0'): | ||
y = scipy.ifft(X) | ||
assert_allclose(y, x) | ||
|
||
# Callable when imported using from | ||
# Historically, scipy.fft was an alias for numpy.fft.fft | ||
# Ensure there are no conflicts with the FFT module (gh-10253) | ||
|
||
# Test must run in a subprocess so scipy.fft is not already imported | ||
subprocess.check_call([sys.executable, '-c', TEST_BODY]) | ||
|
||
# scipy.fft is the correct module | ||
from scipy import fft | ||
with pytest.deprecated_call(match=r'1\.5\.0'): | ||
X = fft(x) | ||
with pytest.deprecated_call(match=r'2\.0\.0'): | ||
y = scipy.ifft(X) | ||
assert_allclose(y, x) | ||
assert not callable(fft) | ||
assert fft.__name__ == 'scipy.fft' | ||
|
||
from scipy import ifft | ||
assert ifft.__wrapped__ is np.fft.ifft | ||
|