Skip to content

[BUG][BLD] revert DEF component of #21878 #21919

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
Jul 15, 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
17 changes: 17 additions & 0 deletions pandas/_libs/src/numpy_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ 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
}

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);
Expand Down
26 changes: 2 additions & 24 deletions pandas/_libs/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ cnp.import_array()

cimport cpython
from cpython cimport PyTypeObject
from cpython.string cimport PyString_FromString, PyString_AsString

DEF PY3 = bytes != str

cdef extern from "Python.h":
# Note: importing extern-style allows us to declare these as nogil
Expand All @@ -17,8 +15,6 @@ cdef extern from "Python.h":
bint PyFloat_Check(object obj) nogil
bint PyComplex_Check(object obj) nogil
bint PyObject_TypeCheck(object obj, PyTypeObject* type) nogil
char* PyUnicode_AsUTF8(object unicode)
object PyUnicode_FromString(const char* u) nogil


cdef extern from "numpy/arrayobject.h":
Expand Down Expand Up @@ -74,6 +70,8 @@ cdef extern from "numpy_helper.h":
int assign_value_1d(ndarray, Py_ssize_t, object) except -1
cnp.int64_t get_nat()
object get_value_1d(ndarray, Py_ssize_t)
char *get_c_string(object) except NULL
object char_to_string(char*)

ctypedef fused numeric:
cnp.int8_t
Expand Down Expand Up @@ -104,26 +102,6 @@ cdef extern from "headers/stdint.h":
enum: INT64_MIN


cdef inline const char* get_c_string(object obj) except NULL:
"""
returns ASCII or UTF8 (py3) view on python str
python object owns memory, should not be freed
"""
# TODO: this docstring is copied verbatim from version that was
# directly in numpy_helper.C; is it still accurate?
IF PY3:
return PyUnicode_AsUTF8(obj)
ELSE:
return PyString_AsString(obj)


cdef inline object char_to_string(const char* data):
IF PY3:
return PyUnicode_FromString(data)
ELSE:
return PyString_FromString(data)


cdef inline object get_value_at(ndarray arr, object loc):
cdef:
Py_ssize_t i, sz
Expand Down
7 changes: 3 additions & 4 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ from tslibs.timestamps cimport (create_timestamp_from_ts,
from tslibs.timestamps import Timestamp


DEF PY2 = str == bytes
cdef bint PY2 = str == bytes


cdef inline object create_datetime_from_ts(
Expand Down Expand Up @@ -555,9 +555,8 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
if len(val) == 0 or val in nat_strings:
iresult[i] = NPY_NAT
continue
if PY2:
if PyUnicode_Check(val):
val = val.encode('utf-8')
if PyUnicode_Check(val) and PY2:
val = val.encode('utf-8')

try:
_string_to_dts(val, &dts, &out_local, &out_tzoffset)
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ from nattype cimport _nat_scalar_rules, NPY_NAT, is_null_datetimelike
from offsets cimport to_offset
from offsets import _Tick

DEF PY2 = str == bytes
cdef bint PY2 = str == bytes


cdef extern from "period_helper.h":
Expand Down Expand Up @@ -728,7 +728,7 @@ cdef object _period_strftime(int64_t value, int freq, object fmt):

result = result.replace(str_extra_fmts[i], repl)

IF PY2:
if PY2:
result = result.decode('utf-8', 'ignore')

return result
Expand Down