Skip to content
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

remove numpy_helper and some unneeded util functions #22469

Merged
merged 1 commit into from
Aug 29, 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: 1 addition & 4 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ cdef class IndexEngine:
loc = self.get_loc(key)
value = convert_scalar(arr, value)

if PySlice_Check(loc) or util.is_array(loc):
arr[loc] = value
else:
util.set_value_at(arr, loc, value)
arr[loc] = value

cpdef get_loc(self, object val):
if is_definitely_invalid_key(val):
Expand Down
12 changes: 3 additions & 9 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
if is_datelike and checknull(v):
result[i] = NPY_NAT
else:
# we can use the unsafe version because we know `result` is mutable
# since it was created from `np.empty`
util.set_value_at_unsafe(result, i, v)
result[i] = v

return result

Expand All @@ -505,9 +503,7 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
ndarray[object] result = np.empty(n, dtype=object)

for i in range(n):
# we can use the unsafe version because we know `result` is mutable
# since it was created from `np.empty`
util.set_value_at_unsafe(result, i, unicode(arr[i]))
result[i] = unicode(arr[i])

return result

Expand All @@ -518,9 +514,7 @@ cpdef ndarray[object] astype_str(ndarray arr):
ndarray[object] result = np.empty(n, dtype=object)

for i in range(n):
# we can use the unsafe version because we know `result` is mutable
# since it was created from `np.empty`
util.set_value_at_unsafe(result, i, str(arr[i]))
result[i] = str(arr[i])

return result

Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ cdef class SeriesBinGrouper:
result = _get_result_array(res,
self.ngroups,
len(self.dummy_arr))

util.assign_value_1d(result, i, res)
result[i] = res

islider.advance(group_size)
vslider.advance(group_size)
Expand Down Expand Up @@ -408,7 +407,7 @@ cdef class SeriesGrouper:
self.ngroups,
len(self.dummy_arr))

util.assign_value_1d(result, lab, res)
result[lab] = res
counts[lab] = group_size
islider.advance(group_size)
vslider.advance(group_size)
Expand Down
31 changes: 0 additions & 31 deletions pandas/_libs/src/numpy_helper.h

This file was deleted.

29 changes: 1 addition & 28 deletions pandas/_libs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ cdef extern from *:
const char *get_c_string(object) except NULL


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)


cdef extern from "src/headers/stdint.h":
enum: UINT8_MAX
enum: UINT16_MAX
Expand Down Expand Up @@ -116,26 +111,4 @@ cdef inline object get_value_at(ndarray arr, object loc):
Py_ssize_t i

i = validate_indexer(arr, loc)
return get_value_1d(arr, i)


cdef inline set_value_at_unsafe(ndarray arr, object loc, object value):
"""Sets a value into the array without checking the writeable flag.

This should be used when setting values in a loop, check the writeable
flag above the loop and then eschew the check on each iteration.
"""
cdef:
Py_ssize_t i

i = validate_indexer(arr, loc)
assign_value_1d(arr, i, value)


cdef inline set_value_at(ndarray arr, object loc, object value):
"""Sets a value into the array after checking that the array is mutable.
"""
if not cnp.PyArray_ISWRITEABLE(arr):
raise ValueError('assignment destination is read-only')

set_value_at_unsafe(arr, loc, value)
return arr[i]
5 changes: 4 additions & 1 deletion pandas/core/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ def _get_val_at(self, loc):
if sp_loc == -1:
return self.fill_value
else:
return libindex.get_value_at(self, sp_loc)
# libindex.get_value_at will end up calling __getitem__,
# so to avoid recursing we need to unwrap `self` so the
# ndarray.__getitem__ implementation is called.
return libindex.get_value_at(np.asarray(self), sp_loc)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure this will be unnecessary after #22325.


@Appender(_index_shared_docs['take'] % _sparray_doc_kwargs)
def take(self, indices, axis=0, allow_fill=True,
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
ts_include = ['pandas/_libs/tslibs/src']


lib_depends = ['pandas/_libs/src/numpy_helper.h',
'pandas/_libs/src/parse_helper.h',
lib_depends = ['pandas/_libs/src/parse_helper.h',
'pandas/_libs/src/compat_helper.h']

np_datetime_headers = [
Expand Down