Skip to content

Commit

Permalink
DEP: remove unique1d, setmember1d and intersect1d_nu.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommers committed Mar 11, 2011
1 parent f791984 commit 44ae46c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 188 deletions.
78 changes: 2 additions & 76 deletions numpy/lib/arraysetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
union1d,
setdiff1d
:Deprecated:
unique1d,
intersect1d_nu,
setmember1d
:Notes:
For floating point arrays, inaccurate results may appear due to usual round-off
Expand All @@ -28,8 +23,8 @@
:Author: Robert Cimrman
"""
__all__ = ['ediff1d', 'unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',
'setmember1d', 'union1d', 'setdiff1d', 'unique', 'in1d']
__all__ = ['ediff1d', 'intersect1d', 'setxor1d', 'union1d', 'setdiff1d',
'unique', 'in1d']

import numpy as np
from numpy.lib.utils import deprecate
Expand Down Expand Up @@ -417,72 +412,3 @@ def setdiff1d(ar1, ar2, assume_unique=False):
return aux
else:
return np.asarray(ar1)[aux == 0]

@deprecate
def unique1d(ar1, return_index=False, return_inverse=False):
"""
This function is deprecated. Use unique() instead.
"""
if return_index:
import warnings
warnings.warn("The order of the output arguments for "
"`return_index` has changed. Before, "
"the output was (indices, unique_arr), but "
"has now been reversed to be more consistent.")

ar = np.asanyarray(ar1).flatten()
if ar.size == 0:
if return_inverse and return_index:
return ar, np.empty(0, np.bool), np.empty(0, np.bool)
elif return_inverse or return_index:
return ar, np.empty(0, np.bool)
else:
return ar

if return_inverse or return_index:
perm = ar.argsort()
aux = ar[perm]
flag = np.concatenate(([True], aux[1:] != aux[:-1]))
if return_inverse:
iflag = np.cumsum(flag) - 1
iperm = perm.argsort()
if return_index:
return aux[flag], perm[flag], iflag[iperm]
else:
return aux[flag], iflag[iperm]
else:
return aux[flag], perm[flag]

else:
ar.sort()
flag = np.concatenate(([True], ar[1:] != ar[:-1]))
return ar[flag]

@deprecate
def intersect1d_nu(ar1, ar2):
"""
This function is deprecated. Use intersect1d()
instead.
"""
# Might be faster than unique1d( intersect1d( ar1, ar2 ) )?
aux = np.concatenate((unique1d(ar1), unique1d(ar2)))
aux.sort()
return aux[aux[1:] == aux[:-1]]

@deprecate
def setmember1d(ar1, ar2):
"""
This function is deprecated. Use in1d(assume_unique=True)
instead.
"""
# We need this to be a stable sort, so always use 'mergesort' here. The
# values from the first array should always come before the values from the
# second array.
ar = np.concatenate( (ar1, ar2 ) )
order = ar.argsort(kind='mergesort')
sar = ar[order]
equal_adj = (sar[1:] == sar[:-1])
flag = np.concatenate( (equal_adj, [False] ) )

indx = order.argsort(kind='mergesort')[:len( ar1 )]
return flag[indx]
65 changes: 0 additions & 65 deletions numpy/lib/benchmarks/bench_arraysetops.py

This file was deleted.

45 changes: 3 additions & 42 deletions numpy/lib/tests/test_arraysetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def test_unique( self ):
assert_array_equal( c, ec )

vals, indices = unique( a, return_index=True )


ed = np.array( [2, 3, 0, 1] )
assert_array_equal(vals, ec)
assert_array_equal(indices, ed)

vals, ind0, ind1 = unique( a, return_index=True,
return_inverse=True )


ee = np.array( [2, 3, 0, 1, 0, 2, 3] )
assert_array_equal(vals, ec)
Expand Down Expand Up @@ -53,21 +53,6 @@ def test_intersect1d( self ):

assert_array_equal([], intersect1d([],[]))

def test_intersect1d_nu( self ):
# This should be removed when intersect1d_nu is removed.
a = np.array( [5, 5, 7, 1, 2] )
b = np.array( [2, 1, 4, 3, 3, 1, 5] )

ec = np.array( [1, 2, 5] )
warnings.filterwarnings('ignore', message='\s*`intersect1d_nu` is deprecated!')
warnings.filterwarnings('ignore', message='\s*`unique1d` is deprecated!')
c = intersect1d_nu( a, b )
assert_array_equal( c, ec )
assert_array_equal([], intersect1d_nu([],[]))
warnings.filters.pop(0)
warnings.filters.pop(0)


def test_setxor1d( self ):
a = np.array( [5, 7, 1, 2] )
b = np.array( [2, 4, 3, 1, 5] )
Expand Down Expand Up @@ -104,30 +89,6 @@ def test_ediff1d(self):
assert_array_equal([],ediff1d(one_elem))
assert_array_equal([1],ediff1d(two_elem))

def test_setmember1d( self ):
# This should be removed when setmember1d is removed.
a = np.array( [5, 7, 1, 2] )
b = np.array( [2, 4, 3, 1, 5] )

ec = np.array( [True, False, True, True] )
warnings.filterwarnings('ignore', '\s*`setmember1d` is deprecated!')
c = setmember1d( a, b )

assert_array_equal( c, ec )

a[0] = 8
ec = np.array( [False, False, True, True] )
c = setmember1d( a, b )
assert_array_equal( c, ec )

a[0], a[3] = 4, 8
ec = np.array( [True, False, True, False] )
c = setmember1d( a, b )
assert_array_equal( c, ec )

assert_array_equal([], setmember1d([],[]))
warnings.filters.pop(0)

def test_in1d(self):
a = np.array( [5, 7, 1, 2] )
b = np.array( [2, 4, 3, 1, 5] )
Expand All @@ -145,7 +106,7 @@ def test_in1d(self):
ec = np.array( [True, False, True, False] )
c = in1d( a, b, assume_unique=True )
assert_array_equal( c, ec )

a = np.array([5,4,5,3,4,4,3,4,3,5,2,1,5,5])
b = [2,3,4]

Expand Down
10 changes: 5 additions & 5 deletions numpy/ma/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ def intersect1d(ar1, ar2, assume_unique=False):
if assume_unique:
aux = ma.concatenate((ar1, ar2))
else:
# Might be faster than unique1d( intersect1d( ar1, ar2 ) )?
# Might be faster than unique( intersect1d( ar1, ar2 ) )?
aux = ma.concatenate((unique(ar1), unique(ar2)))
aux.sort()
return aux[aux[1:] == aux[:-1]]
Expand Down Expand Up @@ -1522,7 +1522,7 @@ def flatnotmasked_edges(a):
See Also
--------
flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges,
flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges,
clump_masked, clump_unmasked
Notes
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def flatnotmasked_contiguous(a):
>>> a = np.ma.arange(10)
>>> np.ma.extras.flatnotmasked_contiguous(a)
slice(0, 10, None)
>>> mask = (a < 3) | (a > 8) | (a == 5)
>>> a[mask] = np.ma.masked
>>> np.array(a[~a.mask])
Expand Down Expand Up @@ -1761,7 +1761,7 @@ def clump_unmasked(a):
See Also
--------
flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
notmasked_contiguous, clump_masked
Examples
Expand Down Expand Up @@ -1805,7 +1805,7 @@ def clump_masked(a):
See Also
--------
flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
notmasked_contiguous, clump_unmasked
Examples
Expand Down

0 comments on commit 44ae46c

Please sign in to comment.