Skip to content

[CLN] Make more of numpy_helper unnecessary #22344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,14 @@ cdef class IndexEngine:
# form the set of the results (like ismember)
members = np.empty(n, dtype=np.uint8)
for i in range(n):
val = util.get_value_1d(values, i)
val = values[i]
if val in stargets:
if val not in d:
d[val] = []
d[val].append(i)

for i in range(n_t):

val = util.get_value_1d(targets, i)
val = targets[i]

# found
if val in d:
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ def infer_dtype(object value, bint skipna=False):

# try to use a valid value
for i in range(n):
val = util.get_value_1d(values, i)
val = values[i]

# do not use is_nul_datetimelike to keep
# np.datetime64('nat') and np.timedelta64('nat')
Expand Down Expand Up @@ -1240,7 +1240,7 @@ def infer_dtype(object value, bint skipna=False):
return 'interval'

for i in range(n):
val = util.get_value_1d(values, i)
val = values[i]
if (util.is_integer_object(val) and
not util.is_timedelta64_object(val) and
not util.is_datetime64_object(val)):
Expand Down Expand Up @@ -2255,7 +2255,7 @@ def fast_multiget(dict mapping, ndarray keys, default=np.nan):
keys = getattr(keys, 'values', keys)

for i in range(n):
val = util.get_value_1d(keys, i)
val = keys[i]
if val in mapping:
output[i] = mapping[val]
else:
Expand Down
16 changes: 0 additions & 16 deletions pandas/_libs/src/numpy_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,4 @@ PANDAS_INLINE PyObject* get_value_1d(PyArrayObject* ap, Py_ssize_t i) {
return PyArray_Scalar(item, PyArray_DESCR(ap), (PyObject*)ap);
}

// returns ASCII or UTF8 (py3) view on python str
// python object owns memory, should not be freed
PANDAS_INLINE const char* get_c_string(PyObject* obj) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_AsUTF8(obj);
#else
return PyString_AsString(obj);
#endif
}

void set_array_not_contiguous(PyArrayObject* ao) {
// Numpy>=1.8-compliant equivalent to:
// ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
PyArray_CLEARFLAGS(ao, (NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS));
}

#endif // PANDAS__LIBS_SRC_NUMPY_HELPER_H_
34 changes: 31 additions & 3 deletions pandas/_libs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@ from cython cimport Py_ssize_t
cimport numpy as cnp
from numpy cimport ndarray

cdef extern from "numpy/ndarraytypes.h":
void PyArray_CLEARFLAGS(ndarray arr, int flags) nogil


cdef extern from "numpy/arrayobject.h":
enum:
NPY_ARRAY_C_CONTIGUOUS
NPY_ARRAY_F_CONTIGUOUS


cdef extern from *:
"""
// returns ASCII or UTF8 (py3) view on python str
// python object owns memory, should not be freed
static const char* get_c_string(PyObject* obj) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_AsUTF8(obj);
#else
return PyString_AsString(obj);
#endif
}
"""
const char *get_c_string(object) except NULL

cdef extern from "src/numpy_helper.h":
void set_array_not_contiguous(ndarray ao)

cdef extern from "src/numpy_helper.h":
int assign_value_1d(ndarray, Py_ssize_t, object) except -1
object get_value_1d(ndarray, Py_ssize_t)
const char *get_c_string(object) except NULL


cdef extern from "src/headers/stdint.h":
Expand Down Expand Up @@ -44,6 +65,13 @@ ctypedef fused numeric:
cnp.float64_t


cdef inline void set_array_not_contiguous(ndarray ao) nogil:
# Numpy>=1.8-compliant equivalent to:
# ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
PyArray_CLEARFLAGS(ao,
(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS))


cdef inline object get_value_at(ndarray arr, object loc):
cdef:
Py_ssize_t i, sz
Expand Down