From 43c8313a3bae730b1f6ef7a35adb935959f892c8 Mon Sep 17 00:00:00 2001 From: hannaro Date: Thu, 19 Feb 2015 14:47:52 +0100 Subject: [PATCH 1/3] BUG: Fixes #5524 and adds test argpartition does not fail anymore on non-ndarray array-likes. Fix as implemented by @maniteja123. --- numpy/core/fromnumeric.py | 10 +++++++++- numpy/core/tests/test_multiarray.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 49fd57e29c34..72d59fd0caa2 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -679,8 +679,16 @@ def argpartition(a, kth, axis=-1, kind='introselect', order=None): >>> x[np.argpartition(x, (1, 3))] array([1, 2, 3, 4]) + >>> x = [3, 4, 2, 1] + >>> np.array(x)[np.argpartition(x, 3)] + array([2, 1, 3, 4]) + """ - return a.argpartition(kth, axis, kind=kind, order=order) + try: + argpartition = a.argpartition + except AttributeError: + return _wrapit(a, 'argpartition',kth, axis, kind, order) + return argpartition(kth, axis, kind=kind, order=order) def sort(a, axis=-1, kind='quicksort', order=None): diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 1ca06500a72b..d9321147169d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1702,6 +1702,12 @@ def test_partition_fuzz(self): assert_array_equal(np.partition(d, kth)[kth], tgt, err_msg="data: %r\n kth: %r" % (d, kth)) + def test_argpartition_gh5524(self): + # A test for functionality of argpartition on lists. + d = [6,7,3,2,9,0] + p = np.argpartition(d,1) + self.assert_partitioned(np.array(d)[p],[1]) + def test_flatten(self): x0 = np.array([[1, 2, 3], [4, 5, 6]], np.int32) x1 = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], np.int32) From 102ba699b8b259072c2ba635f70bb2937450ada8 Mon Sep 17 00:00:00 2001 From: Maniteja Nandana Date: Mon, 22 Dec 2014 02:53:39 +0530 Subject: [PATCH 2/3] BUG: solves complex array clip in issue #5354 and added symmetric regression test --- numpy/core/src/multiarray/arraytypes.c.src | 2 -- numpy/core/tests/test_numeric.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index d3ec0430a93c..3ce25db17d8e 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -3467,8 +3467,6 @@ static void npy_intp i; @type@ max_val, min_val; - min_val = *min; - max_val = *max; if (max != NULL) { max_val = *max; } diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 7f45fe11acfb..a1bc195d7ee9 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -1176,6 +1176,18 @@ def test_simple_complex(self): act = self.clip(a, m, M) assert_array_strict_equal(ac, act) + def test_clip_complex(self): + # Address Issue gh-5354 for clipping complex arrays + # Test native complex input without explicit min/max + # ie, either min=None or max=None + a = np.ones(10, dtype=np.complex) + m = a.min() + M = a.max() + am = self.fastclip(a, m, None) + aM = self.fastclip(a, None, M) + assert_array_strict_equal(am, a) + assert_array_strict_equal(aM, a) + def test_clip_non_contig(self): #Test clip for non contiguous native input and native scalar min/max. a = self._generate_data(self.nr * 2, self.nc * 3) From 7cfdd986cde08ac838eb867d53cdd20ed2b50df3 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sat, 28 Feb 2015 14:02:15 +0100 Subject: [PATCH 3/3] DOC: update release notes --- doc/release/1.9.2-notes.rst | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/doc/release/1.9.2-notes.rst b/doc/release/1.9.2-notes.rst index ea611a289174..857b6fe30b57 100644 --- a/doc/release/1.9.2-notes.rst +++ b/doc/release/1.9.2-notes.rst @@ -6,17 +6,20 @@ This is a bugfix only release in the 1.9.x series. Issues fixed ============ -* `#5316 `__: fix too large dtype alignment of strings and complex types -* `#5424 `__: fix ma.median when used on ndarrays -* `#5481 `__: Fix astype for structured array fields of different byte order -* `#5155 `__: Fix loadtxt with comments=None and a string None data -* `#4476 `__: Masked array view fails if structured dtype has datetime component -* `#5388 `__: Make RandomState.set_state and RandomState.get_state threadsafe -* `#5390 `__: make seed, randint and shuffle threadsafe -* `#5374 `__: Fixed incorrect assert_array_almost_equal_nulp documentation -* `#5393 `__: Add support for ATLAS > 3.9.33. -* `#5313 `__: PyArray_AsCArray caused segfault for 3d arrays -* `#5492 `__: handle out of memory in rfftf -* `#4181 `__: fix a few bugs in the random.pareto docstring -* `#5359 `__: minor changes to linspace docstring -* `#4723 `__: fix a compile issues on AIX +* `#5316 `__: fix too large dtype alignment of strings and complex types +* `#5424 `__: fix ma.median when used on ndarrays +* `#5481 `__: Fix astype for structured array fields of different byte order +* `#5354 `__: fix segfault when clipping complex arrays +* `#5524 `__: allow np.argpartition on non ndarrays +* `#5612 `__: Fixes ndarray.fill to accept full range of uint64 +* `#5155 `__: Fix loadtxt with comments=None and a string None data +* `#4476 `__: Masked array view fails if structured dtype has datetime component +* `#5388 `__: Make RandomState.set_state and RandomState.get_state threadsafe +* `#5390 `__: make seed, randint and shuffle threadsafe +* `#5374 `__: Fixed incorrect assert_array_almost_equal_nulp documentation +* `#5393 `__: Add support for ATLAS > 3.9.33. +* `#5313 `__: PyArray_AsCArray caused segfault for 3d arrays +* `#5492 `__: handle out of memory in rfftf +* `#4181 `__: fix a few bugs in the random.pareto docstring +* `#5359 `__: minor changes to linspace docstring +* `#4723 `__: fix a compile issues on AIX