Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e7c822

Browse files
committed
Fix Ticket #352
1 parent ed7b368 commit 2e7c822

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

THANKS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Francesc Altet for unicode and nested record tests
2424
and much help with rooting out nested record array bugs.
2525
Tim Hochberg for getting the build working on MSVC, optimization
2626
improvements, and code review
27-
Charles Harris for the sorting code originally written for Numarray and for improvements to polyfit, many bug fixes, and documentation strings.
27+
Charles Harris for the sorting code originally written for Numarray and
28+
for improvements to polyfit, many bug fixes, and documentation strings.

numpy/core/src/arrayobject.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,41 +4749,44 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
47494749
static PyObject *
47504750
_check_axis(PyArrayObject *arr, int *axis, int flags)
47514751
{
4752-
PyObject *temp;
4752+
PyObject *temp1, *temp2;
47534753
int n = arr->nd;
47544754

47554755
if ((*axis >= MAX_DIMS) || (n==0)) {
47564756
if (n != 1) {
4757-
temp = PyArray_Ravel(arr,0);
4758-
if (temp) *axis = PyArray_NDIM(temp)-1;
4759-
else *axis = 0;
4757+
temp1 = PyArray_Ravel(arr,0);
4758+
if (temp1 == NULL) {*axis=0; return NULL;}
4759+
*axis = PyArray_NDIM(temp1)-1;
47604760
}
47614761
else {
4762-
temp = (PyObject *)arr;
4763-
Py_INCREF(temp);
4762+
temp1 = (PyObject *)arr;
4763+
Py_INCREF(temp1);
47644764
*axis = 0;
47654765
}
4766-
return temp;
4766+
if (!flags) return temp1;
47674767
}
47684768
else {
4769-
if (flags) {
4770-
temp = PyArray_CheckFromAny((PyObject *)arr, NULL,
4771-
0, 0, flags, NULL);
4772-
if (temp == NULL) return NULL;
4773-
}
4774-
else {
4775-
Py_INCREF(arr);
4776-
temp = (PyObject *)arr;
4777-
}
4769+
temp1 = (PyObject *)arr;
4770+
Py_INCREF(temp1);
47784771
}
4772+
if (flags) {
4773+
temp2 = PyArray_CheckFromAny((PyObject *)temp1, NULL,
4774+
0, 0, flags, NULL);
4775+
Py_DECREF(temp1);
4776+
if (temp2 == NULL) return NULL;
4777+
}
4778+
else {
4779+
temp2 = (PyObject *)temp1;
4780+
}
4781+
n = PyArray_NDIM(temp2);
47794782
if (*axis < 0) *axis += n;
47804783
if ((*axis < 0) || (*axis >= n)) {
47814784
PyErr_Format(PyExc_ValueError,
47824785
"axis(=%d) out of bounds", *axis);
4783-
Py_DECREF(temp);
4786+
Py_DECREF(temp2);
47844787
return NULL;
47854788
}
4786-
return temp;
4789+
return temp2;
47874790
}
47884791

47894792
#include "arraymethods.c"

numpy/core/tests/test_regression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ def check_reshape_order(self, level=rlevel):
537537
a = N.array([[1,2],[3,4],[5,6],[7,8]])
538538
b = a[:,1]
539539
assert_equal(b.reshape(2,2,order='F'), [[2,6],[4,8]])
540+
541+
def check_repeat_discont(self, level=rlevel):
542+
"""Ticket #352"""
543+
a = N.arange(12).reshape(4,3)[:,2]
544+
assert_equal(a.repeat(3), [2,2,2,5,5,5,8,8,8,11,11,11])
545+
540546

541547
if __name__ == "__main__":
542548
NumpyTest().run()

0 commit comments

Comments
 (0)