Skip to content

Remove unused, avoid uses of deprecated api #22071

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 19 commits into from
Jul 31, 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
2 changes: 1 addition & 1 deletion pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def is_lexsorted(list list_of_arrays):
for i in range(nlevels):
arr = list_of_arrays[i]
assert arr.dtype.name == 'int64'
vecs[i] = <int64_t*> arr.data
vecs[i] = <int64_t*> cnp.PyArray_DATA(arr)

# Assume uniqueness??
with nogil:
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ from cython cimport Py_ssize_t
from libc.stdlib cimport malloc, free

import numpy as np
cimport numpy as cnp
from numpy cimport (ndarray,
double_t,
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
uint32_t, uint64_t, float32_t, float64_t)
cnp.import_array()


from util cimport numeric, get_nat
Expand Down Expand Up @@ -118,7 +120,7 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
counts[:] = _counts[1:]

data = np.empty((K, N), dtype=np.float64)
ptr = <float64_t*> data.data
ptr = <float64_t*> cnp.PyArray_DATA(data)

take_2d_axis1_float64_float64(values.T, indexer, out=data)

Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cdef inline bint is_definitely_invalid_key(object val):
return True

# we have a _data, means we are a NDFrame
return (PySlice_Check(val) or cnp.PyArray_Check(val)
return (PySlice_Check(val) or util.is_array(val)
or PyList_Check(val) or hasattr(val, '_data'))


Expand Down Expand Up @@ -104,7 +104,7 @@ cdef class IndexEngine:
void* data_ptr

loc = self.get_loc(key)
if PySlice_Check(loc) or cnp.PyArray_Check(loc):
if PySlice_Check(loc) or util.is_array(loc):
return arr[loc]
else:
return get_value_at(arr, loc, tz=tz)
Expand All @@ -120,7 +120,7 @@ cdef class IndexEngine:
loc = self.get_loc(key)
value = convert_scalar(arr, value)

if PySlice_Check(loc) or cnp.PyArray_Check(loc):
if PySlice_Check(loc) or util.is_array(loc):
arr[loc] = value
else:
util.set_value_at(arr, loc, value)
Expand Down
14 changes: 3 additions & 11 deletions pandas/_libs/src/numpy_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ The full license is in the LICENSE file, distributed with this software.
#include "numpy/arrayscalars.h"


PANDAS_INLINE npy_int64 get_nat(void) { return NPY_MIN_INT64; }

PANDAS_INLINE int assign_value_1d(PyArrayObject* ap, Py_ssize_t _i,
PyObject* v) {
npy_intp i = (npy_intp)_i;
Expand All @@ -40,16 +38,10 @@ PANDAS_INLINE const char* get_c_string(PyObject* obj) {
#endif
}

PANDAS_INLINE PyObject* char_to_string(const char* data) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromString(data);
#else
return PyString_FromString(data);
#endif
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are numpy >= 1.9! can this be simplified?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The existing implementation uses the deprecated numpy API.

// 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_
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,

trans, deltas, typ = get_dst_info(tz)

tdata = <int64_t*> trans.data
tdata = <int64_t*> cnp.PyArray_DATA(trans)
ntrans = len(trans)

result_a = np.empty(n, dtype=np.int64)
Expand Down
Loading