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

Error on C Warnings #32163

Merged
merged 13 commits into from
Mar 19, 2020
4 changes: 2 additions & 2 deletions pandas/_libs/hashtable_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ cdef class StringVector:

append_data_string(self.data, x)

cdef extend(self, ndarray[:] x):
cdef extend(self, ndarray[object] x):
Copy link
Member

Choose a reason for hiding this comment

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

im not sure this is accurate, might be a string dtype? IIRC this class isnt used

for i in range(len(x)):
self.append(x[i])

Expand Down Expand Up @@ -238,7 +238,7 @@ cdef class ObjectVector:
self.external_view_exists = True
return self.ao

cdef extend(self, ndarray[:] x):
cdef extend(self, ndarray[object] x):
for i in range(len(x)):
self.append(x[i])

Expand Down
25 changes: 12 additions & 13 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -378,25 +378,23 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):

object blkno
object group_dict = defaultdict(list)
int64_t[:] res_view

n = blknos.shape[0]

if n == 0:
return

result = list()
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 think there are some "bugs" in Cython with generator functions that were yielding build warnings. I opened an issue on the tracker for it here:

cython/cython#3430

But for now figure OK to just convert to a list instead of a generator func anyway

start = 0
cur_blkno = blknos[start]

if group is False:
if n == 0:
pass
elif group is False:
for i in range(1, n):
if blknos[i] != cur_blkno:
yield cur_blkno, slice(start, i)
result.append((cur_blkno, slice(start, i)))

start = i
cur_blkno = blknos[i]

yield cur_blkno, slice(start, n)
result.append((cur_blkno, slice(start, n)))
else:
for i in range(1, n):
if blknos[i] != cur_blkno:
Expand All @@ -409,19 +407,20 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):

for blkno, slices in group_dict.items():
if len(slices) == 1:
yield blkno, slice(slices[0][0], slices[0][1])
result.append((blkno, slice(slices[0][0], slices[0][1])))
else:
tot_len = sum(stop - start for start, stop in slices)
result = np.empty(tot_len, dtype=np.int64)
res_view = result
arr = np.empty(tot_len, dtype=np.int64)

i = 0
for start, stop in slices:
for diff in range(start, stop):
res_view[i] = diff
arr[i] = diff
i += 1

yield blkno, result
result.append((blkno, arr))

return result


def get_blkno_placements(blknos, group: bool = True):
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ cdef class TextReader:
self._tokenize_rows(1)

header = [ self.names ]
data_line = 0

if self.parser.lines < 1:
field_count = len(header[0])
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/src/ujson/python/date_conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ npy_datetime NpyDateTimeToEpoch(npy_datetime dt, NPY_DATETIMEUNIT base) {
}

/* Convert PyDatetime To ISO C-string. mutates len */
char *PyDateTimeToIso(PyDateTime_Date *obj, NPY_DATETIMEUNIT base,
char *PyDateTimeToIso(PyObject *obj, NPY_DATETIMEUNIT base,
Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently PyDateTime_Date is not considered part of the public API and attempts have been made in the past to privatize:

python/cpython#10238 (comment)

So PyObject seems the right way to go here and gets rid of warnings

size_t *len) {
npy_datetimestruct dts;
int ret;
Expand Down Expand Up @@ -98,7 +98,7 @@ char *PyDateTimeToIso(PyDateTime_Date *obj, NPY_DATETIMEUNIT base,
return result;
}

npy_datetime PyDateTimeToEpoch(PyDateTime_Date *dt, NPY_DATETIMEUNIT base) {
npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) {
npy_datetimestruct dts;
int ret;

Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/src/ujson/python/date_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <numpy/ndarraytypes.h>
#include "datetime.h"

// Scales value inplace from nanosecond resolution to unit resolution
int scaleNanosecToUnit(npy_int64 *value, NPY_DATETIMEUNIT unit);
Expand All @@ -23,10 +22,10 @@ npy_datetime NpyDateTimeToEpoch(npy_datetime dt, NPY_DATETIMEUNIT base);
// up to precision `base` e.g. base="s" yields 2020-01-03T00:00:00Z
// while base="ns" yields "2020-01-01T00:00:00.000000000Z"
// len is mutated to save the length of the returned string
char *PyDateTimeToIso(PyDateTime_Date *obj, NPY_DATETIMEUNIT base, size_t *len);
char *PyDateTimeToIso(PyObject *obj, NPY_DATETIMEUNIT base, size_t *len);

// Convert a Python Date/Datetime to Unix epoch with resolution base
npy_datetime PyDateTimeToEpoch(PyDateTime_Date *dt, NPY_DATETIMEUNIT base);
npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base);

char *int64ToIsoDuration(int64_t value, size_t *len);

Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
} else {
// datetime.* objects don't follow above rules
nanosecVal =
PyDateTimeToEpoch((PyDateTime_Date *)item, NPY_FR_ns);
PyDateTimeToEpoch(item, NPY_FR_ns);
}
}
}
Expand All @@ -1469,8 +1469,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
if (type_num == NPY_DATETIME) {
cLabel = int64ToIso(nanosecVal, base, &len);
} else {
cLabel = PyDateTimeToIso((PyDateTime_Date *)item,
base, &len);
cLabel = PyDateTimeToIso(item, base, &len);
}
}
if (cLabel == NULL) {
Expand Down Expand Up @@ -1683,7 +1682,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
NPY_DATETIMEUNIT base =
((PyObjectEncoder *)tc->encoder)->datetimeUnit;
GET_TC(tc)->longValue =
PyDateTimeToEpoch((PyDateTime_Date *)obj, base);
PyDateTimeToEpoch(obj, base);
tc->type = JT_LONG;
}
return;
Expand All @@ -1710,7 +1709,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
NPY_DATETIMEUNIT base =
((PyObjectEncoder *)tc->encoder)->datetimeUnit;
GET_TC(tc)->longValue =
PyDateTimeToEpoch((PyDateTime_Date *)obj, base);
PyDateTimeToEpoch(obj, base);
tc->type = JT_LONG;
}
return;
Expand Down
10 changes: 4 additions & 6 deletions pandas/_libs/tslibs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#endif // NPY_NO_DEPRECATED_API

#include <Python.h>
#include <datetime.h>

#include <numpy/arrayobject.h>
#include <numpy/arrayscalars.h>
Expand Down Expand Up @@ -313,15 +312,14 @@ int cmp_npy_datetimestruct(const npy_datetimestruct *a,
* object into a NumPy npy_datetimestruct. Uses tzinfo (if present)
* to convert to UTC time.
*
* While the C API has PyDate_* and PyDateTime_* functions, the following
* implementation just asks for attributes, and thus supports
* datetime duck typing. The tzinfo time zone conversion would require
* this style of access anyway.
* The following implementation just asks for attributes, and thus
* supports datetime duck typing. The tzinfo time zone conversion
* requires this style of access as well.
*
* Returns -1 on error, 0 on success, and 1 (with no error set)
* if obj doesn't have the needed date or datetime attributes.
*/
int convert_pydatetime_to_datetimestruct(PyDateTime_Date *dtobj,
int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
npy_datetimestruct *out) {
// Assumes that obj is a valid datetime object
PyObject *tmp;
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/src/datetime/np_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#endif // NPY_NO_DEPRECATED_API

#include <numpy/ndarraytypes.h>
#include <datetime.h>

typedef struct {
npy_int64 days;
Expand All @@ -35,7 +34,7 @@ extern const npy_datetimestruct _NS_MAX_DTS;
// stuff pandas needs
// ----------------------------------------------------------------------------

int convert_pydatetime_to_datetimestruct(PyDateTime_Date *dtobj,
int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
npy_datetimestruct *out);

npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ def run(self):
extra_compile_args.append("/Z7")
extra_link_args.append("/DEBUG")
else:
# args to ignore warnings
extra_compile_args = []
extra_compile_args = ["-Werror"]
extra_link_args = []
if debugging_symbols_requested:
extra_compile_args.append("-g")
Expand Down Expand Up @@ -477,6 +476,14 @@ def run(self):
# we can't do anything about these warnings because they stem from
# cython+numpy version mismatches.
macros.append(("NPY_NO_DEPRECATED_API", "0"))
if "-Werror" in extra_compile_args:
try:
import numpy as np
except ImportError:
pass
else:
if np.__version__ < LooseVersion("1.16.0"):
extra_compile_args.remove("-Werror")


# ----------------------------------------------------------------------
Expand Down