Skip to content

Commit

Permalink
CLN: remove build warnings from tslib.pyx, saslib.pyx, some from lib.…
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback authored Jan 30, 2017
1 parent b1c3c48 commit c26e5bb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pandas/io/sas/saslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ cdef class Parser(object):
self.current_page_subheaders_count =\
self.parser._current_page_subheaders_count

cdef bint readline(self):
cdef readline(self):

cdef:
int offset, bit_offset, align_correction
Expand Down
94 changes: 49 additions & 45 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cimport numpy as np
cimport cython
import numpy as np
import sys
cdef bint PY3 = (sys.version_info[0] >= 3)

from numpy cimport *

Expand Down Expand Up @@ -42,7 +43,6 @@ cdef extern from "Python.h":
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
Py_ssize_t *slicelength) except -1


cimport cpython

isnan = np.isnan
Expand Down Expand Up @@ -1568,62 +1568,65 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
int64_t cur_blkno
Py_ssize_t i, start, stop, n, diff

object blkno
list group_order
dict group_slices
int64_t[:] res_view

n = blknos.shape[0]

if n > 0:
start = 0
cur_blkno = blknos[start]
if n == 0:
return

if group == False:
for i in range(1, n):
if blknos[i] != cur_blkno:
yield cur_blkno, slice(start, i)
start = 0
cur_blkno = blknos[start]

start = i
cur_blkno = blknos[i]
if group == False:
for i in range(1, n):
if blknos[i] != cur_blkno:
yield cur_blkno, slice(start, i)

yield cur_blkno, slice(start, n)
else:
group_order = []
group_dict = {}

for i in range(1, n):
if blknos[i] != cur_blkno:
if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, i)]
else:
group_dict[cur_blkno].append((start, i))

start = i
cur_blkno = blknos[i]

if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, n)]
else:
group_dict[cur_blkno].append((start, n))
start = i
cur_blkno = blknos[i]

for blkno in group_order:
slices = group_dict[blkno]
if len(slices) == 1:
yield blkno, slice(slices[0][0], slices[0][1])
yield cur_blkno, slice(start, n)
else:
group_order = []
group_dict = {}

for i in range(1, n):
if blknos[i] != cur_blkno:
if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, i)]
else:
tot_len = sum(stop - start for start, stop in slices)
result = np.empty(tot_len, dtype=np.int64)
res_view = result
group_dict[cur_blkno].append((start, i))

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

yield blkno, result
if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, n)]
else:
group_dict[cur_blkno].append((start, n))

for blkno in group_order:
slices = group_dict[blkno]
if len(slices) == 1:
yield 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

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

yield blkno, result


@cython.boundscheck(False)
Expand Down Expand Up @@ -1670,7 +1673,7 @@ cpdef slice_canonize(slice s):
Convert slice to canonical bounded form.
"""
cdef:
Py_ssize_t start, stop, step, length
Py_ssize_t start = 0, stop = 0, step = 1, length

if s.step is None:
step = 1
Expand Down Expand Up @@ -1727,6 +1730,7 @@ cpdef slice_get_indices_ex(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX):

PySlice_GetIndicesEx(<PySliceObject *>slc, objlen,
&start, &stop, &step, &length)

return start, stop, step, length


Expand Down
4 changes: 0 additions & 4 deletions pandas/src/datetime_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ The full license is in the LICENSE file, distributed with this software.
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"

#if PY_MAJOR_VERSION >= 3
#define PyInt_AS_LONG PyLong_AsLong
#endif

npy_int64 get_long_attr(PyObject *o, const char *attr) {
npy_int64 long_val;
PyObject *value = PyObject_GetAttrString(o, attr);
Expand Down
19 changes: 7 additions & 12 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
from datetime cimport get_datetime64_value, get_timedelta64_value
import numpy as np

# GH3363
from sys import version_info
cdef bint PY2 = version_info[0] == 2
cdef bint PY3 = not PY2
import sys
cdef bint PY3 = (sys.version_info[0] >= 3)

from cpython cimport (
PyTypeObject,
Expand All @@ -24,11 +22,8 @@ from cpython cimport (
PyUnicode_AsUTF8String,
)


# Cython < 0.17 doesn't have this in cpython
cdef extern from "Python.h":
cdef PyTypeObject *Py_TYPE(object)
int PySlice_Check(object)

cdef extern from "datetime_helper.h":
double total_seconds(object)
Expand Down Expand Up @@ -2121,8 +2116,8 @@ _DEFAULT_DATETIME = datetime(1, 1, 1).replace(
hour=0, minute=0, second=0, microsecond=0)
_MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
_MONTH_NUMBERS = dict((k, i) for i, k in enumerate(_MONTHS))
_MONTH_ALIASES = dict((k + 1, v) for k, v in enumerate(_MONTHS))
_MONTH_NUMBERS = {k: i for i, k in enumerate(_MONTHS)}
_MONTH_ALIASES = {(k + 1): v for k, v in enumerate(_MONTHS)}


cpdef object _get_rule_month(object source, object default='DEC'):
Expand Down Expand Up @@ -5529,8 +5524,8 @@ class TimeRE(dict):
'B': self.__seqToRE(self.locale_time.f_month[1:], 'B'),
'b': self.__seqToRE(self.locale_time.a_month[1:], 'b'),
'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
for tz in tz_names),
'Z': self.__seqToRE([tz for tz_names in self.locale_time.timezone
for tz in tz_names],
'Z'),
'%': '%'})
base.__setitem__('W', base.__getitem__('U').replace('U', 'W'))
Expand All @@ -5553,7 +5548,7 @@ class TimeRE(dict):
break
else:
return ''
regex = '|'.join(re_escape(stuff) for stuff in to_convert)
regex = '|'.join([re_escape(stuff) for stuff in to_convert])
regex = '(?P<%s>%s' % (directive, regex)
return '%s)' % regex

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def pxd(name):

tseries_depends = ['pandas/src/datetime/np_datetime.h',
'pandas/src/datetime/np_datetime_strings.h',
'pandas/src/datetime_helper.h',
'pandas/src/period_helper.h',
'pandas/src/datetime.pxd']

Expand Down Expand Up @@ -584,6 +585,7 @@ def pxd(name):

ujson_ext = Extension('pandas.json',
depends=['pandas/src/ujson/lib/ultrajson.h',
'pandas/src/datetime_helper.h',
'pandas/src/numpy_helper.h'],
sources=['pandas/src/ujson/python/ujson.c',
'pandas/src/ujson/python/objToJSON.c',
Expand Down

0 comments on commit c26e5bb

Please sign in to comment.