10000 DEP,MAINT: Remove old_behavior keyword from numeric.correlate. · numpy/numpy@bac2fdf · GitHub
[go: up one dir, main page]

Skip to content

Commit bac2fdf

Browse files
committed
DEP,MAINT: Remove old_behavior keyword from numeric.correlate.
Risky perhaps. The old correlate behavior was deprecated in NumPy 1.4 and the default behavior changed to the new (standard) version in 1.5. The old function, with slightly different signature, is still available in numpy.core.multiarray.correlate. If this causes problems in the 1.10 release process, this commit can be reverted.
1 parent ec4e91b commit bac2fdf

File tree

3 files changed

+19
-61
lines changed

3 files changed

+19
-61
lines changed

doc/release/1.10.0-notes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Dropped Support:
3232
* try_run and get_output have been removed from
3333
numpy/distutils/command/config.py
3434
* The a._format attribute is no longer supported for array printing.
35-
* Keywords ``skiprows`` and ``missing`` removed from genfromtxt.
35+
* Keywords ``skiprows`` and ``missing`` removed from np.genfromtxt.
36+
* Keyword ``old_behavior`` removed from np.correlate.
3637

3738
Future Changes:
3839

numpy/core/numeric.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def _mode_from_name(mode):
831831
return _mode_from_name_dict[mode.lower()[0]]
832832
return mode
833833

834-
def correlate(a, v, mode='valid', old_behavior=False):
834+
def correlate(a, v, mode='valid'):
835835
"""
836836
Cross-correlation of two 1-dimensional sequences.
837837
@@ -851,10 +851,8 @@ def correlate(a, v, mode='valid', old_behavior=False):
851851
Refer to the `convolve` docstring. Note that the default
852852
is `valid`, unlike `convolve`, which uses `full`.
853853
old_behavior : bool
854-
If True, uses the old behavior from Numeric,
855-
(correlate(a,v) == correlate(v,a), and the conjugate is not taken
856-
for complex arrays). If False, uses the conventional signal
857-
processing definition.
854+
`old_behavior` was removed in NumPy 1.10. If you need the old
855+
behavior, use `multiarray.correlate`.
858856
859857
Returns
860858
-------
@@ -864,6 +862,7 @@ def correlate(a, v, mode='valid', old_behavior=False):
864862
See Also
865863
--------
866864
convolve : Discrete, linear convolution of two one-dimensional sequences.
865+
multiarray.correlate : Old, no conjugate, version of correlate.
867866
868867
Notes
869868
-----
@@ -897,20 +896,7 @@ def correlate(a, v, mode='valid', old_behavior=False):
897896
898897
"""
899898
mode = _mode_from_name(mode)
900-
# the old behavior should be made available under a different name, see thread
901-
# http://thread.gmane.org/gmane.comp.python.numeric.general/12609/focus=12630
902-
if old_behavior:
903-
# 2009-07-18 Cannot remove without replacement function.
904-
warnings.warn("""
905-
The old behavior of correlate was deprecated for 1.4.0, and will be completely removed
906-
for NumPy 2.0.
907-
908-
The new behavior fits the conventional definition of correlation: inputs are
909-
never swapped, and the second argument is conjugated for complex arrays.""",
910-
DeprecationWarning)
911-
return multiarray.correlate(a, v, mode)
912-
else:
913-
return multiarray.correlate2(a, v, mode)
899+
return multiarray.correlate2(a, v, mode)
914900

915901
def convolve(a,v,mode='full'):
916902
"""

numpy/core/tests/test_numeric.py

Lines changed: 12 additions & 41 deletions
2015
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ def test_negative(self):
980980
assert_equal(binary_repr(-1), '-1')
981981
assert_equal(binary_repr(-1, width=8), '11111111')
982982

983+
983984
class TestBaseRepr(TestCase):
984985
def test_base3(self):
985986
assert_equal(base_repr(3**5, 3), '100000')
@@ -1946,7 +1947,7 @@ def test_filled_like(self):
19461947
self.check_like_function(np.full_like, 123.456, True)
19471948
self.check_like_function(np.full_like, np.inf, True)
19481949

1949-
class _TestCorrelate(TestCase):
1950+
class TestCorrelate(TestCase):
19501951
def _setup(self, dt):
19511952
self.x = np.array([1, 2, 3, 4, 5], dtype=dt)
19521953
self.xs = np.arange(1, 20)[::3]
@@ -1961,24 +1962,24 @@ def _setup(self, dt):
19611962

19621963
def test_float(self):
19631964
self._setup(np.float)
1964-
z = np.correlate(self.x, self.y, 'full', old_behavior=self.old_behavior)
1965+
z = np.correlate(self.x, self.y, 'full')
19651966
assert_array_almost_equal(z, self.z1)
1966-
z = np.correlate(self.x, self.y[:-1], 'full', old_behavior=self.old_behavior)
1967+
z = np.correlate(self.x, self.y[:-1], 'full')
19671968
assert_array_almost_equal(z, self.z1_4)
1968-
z = np.correlate(self.y, self.x, 'full', old_behavior=self.old_behavior)
1969+
z = np.correlate(self.y, self.x, 'full')
19691970
assert_array_almost_equal(z, self.z2)
1970-
z = np.correlate(self.x[::-1], self.y, 'full', old_behavior=self.old_behavior)
1971+
z = np.correlate(self.x[::-1], self.y, 'full')
19711972
assert_array_almost_equal(z, self.z1r)
1972-
z = np.correlate(self.y, self.x[::-1], 'full', old_behavior=self.old_behavior)
1973+
z = np.correlate(self.y, self.x[::-1], 'full')
19731974
assert_array_almost_equal(z, self.z2r)
1974-
z = np.correlate(self.xs, self.y, 'full', old_behavior=self.old_behavior)
1975+
z = np.correlate(self.xs, self.y, 'full')
19751976
assert_array_almost_equal(z, self.zs)
19761977

19771978
def test_object(self):
19781979
self._setup(Decimal)
1979-
z = np.correlate(self.x, self.y, 'full', old_behavior=self.old_behavior)
1980+
z = np.correlate(self.x, self.y, 'full')
19801981
assert_array_almost_equal(z, self.z1)
1981-
z = np.correlate(self.y, self.x, 'full', old_behavior=self.old_behavior)
1982+
z = np.correlate(self.y, self.x, 'full')
19821983
assert_array_almost_equal(z, self.z2)
19831984

19841985
def test_no_overwrite(self):
@@ -1988,45 +1989,15 @@ def test_no_overwrite(self):
19881989
assert_array_equal(d, np.ones(100))
19891990
assert_array_equal(k, np.ones(3))
19901991

1991-
class TestCorrelate(_TestCorrelate):
1992-
old_behavior = True
1993-
def _setup(self, dt):
1994-
# correlate uses an unconventional definition so that correlate(a, b)
1995-
# == correlate(b, a), so force the corresponding outputs to be the same
1996-
# as well
1997-
_TestCorrelate._setup(self, dt)
1998-
self.z2 = self.z1
1999-
self.z2r = self.z1r
2000-
2001-
@dec.deprecated()
2002-
def test_complex(self):
2003-
x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
2004-
y = np.array([-1, -2j, 3+1j], dtype=np.complex)
2005-
r_z = np.array([3+1j, 6, 8-1j, 9+1j, -1-8j, -4-1j], dtype=np.complex)
2006-
z = np.correlate(x, y, 'full', old_behavior=self.old_behavior)
2007-
assert_array_almost_equal(z, r_z)
2008-
2009-
@dec.deprecated()
2010-
def test_float(self):
2011-
_TestCorrelate.test_float(self)
2012-
2013-
@dec.deprecated()
2014-
def test_object(self):
-
_TestCorrelate.test_object(self)
2016-
2017-
class TestCorrelateNew(_TestCorrelate):
2018-
old_behavior = False
20191992
def test_complex(self):
20201993
x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
20211994
y = np.array([-1, -2j, 3+1j], dtype=np.complex)
20221995
r_z = np.array([3-1j, 6, 8+1j, 11+5j, -5+8j, -4-1j], dtype=np.complex)
2023-
#z = np.acorrelate(x, y, 'full')
2024-
#assert_array_almost_equal(z, r_z)
2025-
20261996
r_z = r_z[::-1].conjugate()
2027-
z = np.correlate(y, x, 'full', old_behavior=self.old_behavior)
1997+
z = correlate(y, x, mode='full')
20281998
assert_array_almost_equal(z, r_z)
20291999

2000+
20302001
class TestConvolve(TestCase):
20312002
def test_object(self):
20322003
d = [1.] * 100

0 commit comments

Comments
 (0)
0