Skip to content

Commit e28d2a6

Browse files
jbrockmendeljreback
authored andcommittedAug 29, 2018
remove numpy_helper and some unneeded util functions (pandas-dev#22469)
1 parent d1986fd commit e28d2a6

File tree

7 files changed

+12
-78
lines changed

7 files changed

+12
-78
lines changed
 

‎pandas/_libs/index.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ cdef class IndexEngine:
104104
loc = self.get_loc(key)
105105
value = convert_scalar(arr, value)
106106

107-
if PySlice_Check(loc) or util.is_array(loc):
108-
arr[loc] = value
109-
else:
110-
util.set_value_at(arr, loc, value)
107+
arr[loc] = value
111108

112109
cpdef get_loc(self, object val):
113110
if is_definitely_invalid_key(val):

‎pandas/_libs/lib.pyx

+3-9
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
492492
if is_datelike and checknull(v):
493493
result[i] = NPY_NAT
494494
else:
495-
# we can use the unsafe version because we know `result` is mutable
496-
# since it was created from `np.empty`
497-
util.set_value_at_unsafe(result, i, v)
495+
result[i] = v
498496

499497
return result
500498

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

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

512508
return result
513509

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

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

525519
return result
526520

‎pandas/_libs/reduction.pyx

+2-3
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ cdef class SeriesBinGrouper:
280280
result = _get_result_array(res,
281281
self.ngroups,
282282
len(self.dummy_arr))
283-
284-
util.assign_value_1d(result, i, res)
283+
result[i] = res
285284

286285
islider.advance(group_size)
287286
vslider.advance(group_size)
@@ -406,7 +405,7 @@ cdef class SeriesGrouper:
406405
self.ngroups,
407406
len(self.dummy_arr))
408407

409-
util.assign_value_1d(result, lab, res)
408+
result[lab] = res
410409
counts[lab] = group_size
411410
islider.advance(group_size)
412411
vslider.advance(group_size)

‎pandas/_libs/src/numpy_helper.h

-31
This file was deleted.

‎pandas/_libs/util.pxd

+1-28
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ cdef extern from *:
3030
const char *get_c_string(object) except NULL
3131

3232

33-
cdef extern from "src/numpy_helper.h":
34-
int assign_value_1d(ndarray, Py_ssize_t, object) except -1
35-
object get_value_1d(ndarray, Py_ssize_t)
36-
37-
3833
cdef extern from "src/headers/stdint.h":
3934
enum: UINT8_MAX
4035
enum: UINT16_MAX
@@ -116,26 +111,4 @@ cdef inline object get_value_at(ndarray arr, object loc):
116111
Py_ssize_t i
117112

118113
i = validate_indexer(arr, loc)
119-
return get_value_1d(arr, i)
120-
121-
122-
cdef inline set_value_at_unsafe(ndarray arr, object loc, object value):
123-
"""Sets a value into the array without checking the writeable flag.
124-
125-
This should be used when setting values in a loop, check the writeable
126-
flag above the loop and then eschew the check on each iteration.
127-
"""
128-
cdef:
129-
Py_ssize_t i
130-
131-
i = validate_indexer(arr, loc)
132-
assign_value_1d(arr, i, value)
133-
134-
135-
cdef inline set_value_at(ndarray arr, object loc, object value):
136-
"""Sets a value into the array after checking that the array is mutable.
137-
"""
138-
if not cnp.PyArray_ISWRITEABLE(arr):
139-
raise ValueError('assignment destination is read-only')
140-
141-
set_value_at_unsafe(arr, loc, value)
114+
return arr[i]

‎pandas/core/sparse/array.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,10 @@ def _get_val_at(self, loc):
446446
if sp_loc == -1:
447447
return self.fill_value
448448
else:
449-
return libindex.get_value_at(self, sp_loc)
449+
# libindex.get_value_at will end up calling __getitem__,
450+
# so to avoid recursing we need to unwrap `self` so the
451+
# ndarray.__getitem__ implementation is called.
452+
return libindex.get_value_at(np.asarray(self), sp_loc)
450453

451454
@Appender(_index_shared_docs['take'] % _sparray_doc_kwargs)
452455
def take(self, indices, axis=0, allow_fill=True,

‎setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
491491
ts_include = ['pandas/_libs/tslibs/src']
492492

493493

494-
lib_depends = ['pandas/_libs/src/numpy_helper.h',
495-
'pandas/_libs/src/parse_helper.h',
494+
lib_depends = ['pandas/_libs/src/parse_helper.h',
496495
'pandas/_libs/src/compat_helper.h']
497496

498497
np_datetime_headers = [

0 commit comments

Comments
 (0)