summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2007-06-30 14:42:31 +0000
committerCharles Harris <charlesr.harris@gmail.com>2007-06-30 14:42:31 +0000
commit57042ccc48c75b9c8c94cd350fc8d289ff79436a (patch)
treeef9a3e8fd86b314a94a50203e2c2c3d66fc6aae3
parent4c49c1891382a2320ab8c3dcfce0e80487906cff (diff)
downloadnumpy-57042ccc48c75b9c8c94cd350fc8d289ff79436a.tar.gz
Replace <= by < in the insertion sort part of argsort(kind='mergesort')
for strings. Fixes ticket #540.
-rw-r--r--numpy/add_newdocs.py10
-rw-r--r--numpy/core/src/_sortmodule.c.src6
-rw-r--r--numpy/core/tests/test_regression.py6
3 files changed, 14 insertions, 8 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 7b04ee2f4..6efb99a8d 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -367,7 +367,7 @@ add_newdoc('numpy.core.multiarray','lexsort',
sort order, and so on). The keys argument must be a sequence of things
that can be converted to arrays of the same shape.
- :Parameters:
+ Parameters:
a : array type
Array containing values that the returned indices should sort.
@@ -376,16 +376,16 @@ add_newdoc('numpy.core.multiarray','lexsort',
Axis to be indirectly sorted. None indicates that the flattened
array should be used. Default is -1.
- :Returns:
+ Returns:
indices : integer array
Array of indices that sort the keys along the specified axis. The
array has the same shape as the keys.
- :SeeAlso:
+ SeeAlso:
- - argsort : indirect sort
- - sort : inplace sort
+ argsort : indirect sort
+ sort : inplace sort
""")
diff --git a/numpy/core/src/_sortmodule.c.src b/numpy/core/src/_sortmodule.c.src
index 4aa5962ee..495c48d15 100644
--- a/numpy/core/src/_sortmodule.c.src
+++ b/numpy/core/src/_sortmodule.c.src
@@ -377,7 +377,7 @@ static void
*pi = *pj;
}
for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) {
- if (@comp@(v+(*pk)*len,v+(*pj)*len,len)<=0) {
+ if (@comp@(v+(*pk)*len,v+(*pj)*len,len) <= 0) {
*pm = *pk;
++pk;
}else{
@@ -393,8 +393,8 @@ static void
for(pi = pl + 1; pi <= pr; ++pi) {
vi = *pi;
vp = v + vi*len;
- for(pj = pi, pk = pi - 1; \
- pj > pl && (@comp@(vp, v+(*pk)*len,len)<=0); \
+ for(pj = pi, pk = pi - 1; \
+ pj > pl && (@comp@(vp, v+(*pk)*len,len) < 0);\
--pj, --pk) {
*pj = *pk;
}
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 526b34ee1..ab4634eed 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -687,5 +687,11 @@ class test_regression(NumpyTestCase):
x = N.random.rand(*(2,)*16)
y = x.transpose(range(16))
+ def check_string_mergesort(self, level=rlevel):
+ """Ticket #540"""
+ x = N.array(['a']*32)
+ assert_array_equal(x.argsort(kind='m'), N.arange(32))
+
+
if __name__ == "__main__":
NumpyTest().run()