Skip to content

remove get_value_box since it is redundant with libindex.get_value_at #18371

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 2 commits into from
Nov 20, 2017
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
25 changes: 25 additions & 0 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ def get_value_at(ndarray arr, object loc):
return util.get_value_at(arr, loc)


cpdef object get_value_box(ndarray arr, object loc):
cdef:
Copy link
Contributor

Choose a reason for hiding this comment

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

if you can add a doc string at some point

Py_ssize_t i, sz

if util.is_float_object(loc):
casted = int(loc)
if casted == loc:
loc = casted
i = <Py_ssize_t> loc
sz = cnp.PyArray_SIZE(arr)

if i < 0 and sz > 0:
i += sz

if i >= sz or sz == 0 or i < 0:
raise IndexError('index out of bounds')

if arr.descr.type_num == NPY_DATETIME:
return Timestamp(util.get_value_1d(arr, i))
elif arr.descr.type_num == NPY_TIMEDELTA:
return Timedelta(util.get_value_1d(arr, i))
else:
return util.get_value_1d(arr, i)


def set_value_at(ndarray arr, object loc, object val):
return util.set_value_at(arr, loc, val)

Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ cdef extern from "headers/stdint.h":
cdef inline object get_value_at(ndarray arr, object loc):
cdef:
Py_ssize_t i, sz
void* data_ptr
int casted

if is_float_object(loc):
casted = int(loc)
if casted == loc:
Expand Down
27 changes: 1 addition & 26 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

cimport numpy as np
from numpy cimport (int32_t, int64_t, import_array, ndarray,
float64_t, NPY_DATETIME, NPY_TIMEDELTA)
float64_t)
import numpy as np

import sys
Expand Down Expand Up @@ -848,31 +848,6 @@ cdef inline bint _check_all_nulls(object val):
return res


cpdef object get_value_box(ndarray arr, object loc):
cdef:
Py_ssize_t i, sz

if is_float_object(loc):
casted = int(loc)
if casted == loc:
loc = casted
i = <Py_ssize_t> loc
sz = np.PyArray_SIZE(arr)

if i < 0 and sz > 0:
i += sz

if i >= sz or sz == 0 or i < 0:
raise IndexError('index out of bounds')

if arr.descr.type_num == NPY_DATETIME:
return Timestamp(util.get_value_1d(arr, i))
elif arr.descr.type_num == NPY_TIMEDELTA:
return Timedelta(util.get_value_1d(arr, i))
else:
return util.get_value_1d(arr, i)


# Add the min and max fields at the class level
cdef int64_t _NS_UPPER_BOUND = INT64_MAX
# the smallest value we could actually represent is
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ def get_value(self, series, key):
raise

try:
return libts.get_value_box(s, key)
return libindex.get_value_box(s, key)
except IndexError:
raise
except TypeError:
Expand Down