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

Update imports, use nogil version of sqrt #18557

Merged
merged 5 commits into from
Dec 4, 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
2 changes: 1 addition & 1 deletion pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ from numpy cimport (ndarray,
cdef double NaN = <double> np.NaN
cdef double nan = NaN

from libc.math cimport sqrt, fabs
from libc.math cimport fabs, sqrt

# this is our util.pxd
from util cimport numeric, get_nat
Expand Down
35 changes: 19 additions & 16 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# cython: profile=False
cimport numpy as np
cimport cython
import numpy as np
import sys
import operator

cdef bint PY3 = (sys.version_info[0] >= 3)

from numpy cimport *
cimport cython
from cython cimport Py_ssize_t

import numpy as np
cimport numpy as np
from numpy cimport (ndarray, PyArray_NDIM, PyArray_GETITEM, PyArray_SETITEM,
PyArray_ITER_DATA, PyArray_ITER_NEXT, PyArray_IterNew,
flatiter, NPY_OBJECT,
int64_t,
float32_t, float64_t,
uint8_t, uint64_t,
complex128_t)
# initialize numpy
np.import_array()
np.import_ufunc()
Expand Down Expand Up @@ -57,12 +62,12 @@ from tslib import NaT, Timestamp, Timedelta, array_to_datetime
from interval import Interval
from missing cimport checknull

cdef int64_t NPY_NAT = util.get_nat()

cimport util
cdef int64_t NPY_NAT = util.get_nat()
from util cimport is_array, _checknull

from libc.math cimport sqrt, fabs
from libc.math cimport fabs, sqrt


def values_from_object(object o):
Expand Down Expand Up @@ -494,7 +499,6 @@ def maybe_booleans_to_slice(ndarray[uint8_t] mask):
@cython.wraparound(False)
@cython.boundscheck(False)
def scalar_compare(ndarray[object] values, object val, object op):
import operator
cdef:
Py_ssize_t i, n = len(values)
ndarray[uint8_t, cast=True] result
Expand Down Expand Up @@ -529,7 +533,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
result[i] = True
else:
try:
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
result[i] = PyObject_RichCompareBool(x, val, flag)
except (TypeError):
result[i] = True
elif flag == cpython.Py_EQ:
Expand All @@ -541,7 +545,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
result[i] = False
else:
try:
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
result[i] = PyObject_RichCompareBool(x, val, flag)
except (TypeError):
result[i] = False

Expand All @@ -553,7 +557,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
elif isnull_val:
result[i] = False
else:
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
result[i] = PyObject_RichCompareBool(x, val, flag)

return result.view(bool)

Expand Down Expand Up @@ -582,7 +586,6 @@ cpdef bint array_equivalent_object(object[:] left, object[:] right):
@cython.wraparound(False)
@cython.boundscheck(False)
def vec_compare(ndarray[object] left, ndarray[object] right, object op):
import operator
cdef:
Py_ssize_t i, n = len(left)
ndarray[uint8_t, cast=True] result
Expand Down Expand Up @@ -617,7 +620,7 @@ def vec_compare(ndarray[object] left, ndarray[object] right, object op):
if checknull(x) or checknull(y):
result[i] = True
else:
result[i] = cpython.PyObject_RichCompareBool(x, y, flag)
result[i] = PyObject_RichCompareBool(x, y, flag)
else:
for i in range(n):
x = left[i]
Expand All @@ -626,7 +629,7 @@ def vec_compare(ndarray[object] left, ndarray[object] right, object op):
if checknull(x) or checknull(y):
result[i] = False
else:
result[i] = cpython.PyObject_RichCompareBool(x, y, flag)
result[i] = PyObject_RichCompareBool(x, y, flag)

return result.view(bool)

Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from numpy cimport ndarray
cimport numpy as cnp
cimport cpython


cdef extern from "numpy_helper.h":
void set_array_not_contiguous(ndarray ao)

Expand Down
17 changes: 8 additions & 9 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin)
from pandas.tseries.offsets import (
DateOffset, generate_range, Tick, CDay, prefix_mapping)
from pandas.core.tools.datetimes import (
parse_time_string, normalize_date, to_time)

from pandas.core.tools.timedeltas import to_timedelta
from pandas.util._decorators import (Appender, cache_readonly,
deprecate_kwarg, Substitution)
Expand All @@ -55,7 +54,7 @@
from pandas._libs import (lib, index as libindex, tslib as libts,
algos as libalgos, join as libjoin,
Timestamp)
from pandas._libs.tslibs import (timezones, conversion, fields,
from pandas._libs.tslibs import (timezones, conversion, fields, parsing,
period as libperiod)

# -------- some conversion wrapper functions
Expand Down Expand Up @@ -524,14 +523,14 @@ def _generate(cls, start, end, periods, name, offset,

if start is not None:
if normalize:
start = normalize_date(start)
start = libts.normalize_date(start)
_normalized = True
else:
_normalized = _normalized and start.time() == _midnight

if end is not None:
if normalize:
end = normalize_date(end)
end = libts.normalize_date(end)
_normalized = True
else:
_normalized = _normalized and end.time() == _midnight
Expand Down Expand Up @@ -1529,7 +1528,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
if isinstance(label, compat.string_types):
freq = getattr(self, 'freqstr',
getattr(self, 'inferred_freq', None))
_, parsed, reso = parse_time_string(label, freq)
_, parsed, reso = parsing.parse_time_string(label, freq)
lower, upper = self._parsed_string_to_bounds(reso, parsed)
# lower, upper form the half-open interval:
# [parsed, parsed + 1 freq)
Expand All @@ -1546,7 +1545,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
freq = getattr(self, 'freqstr',
getattr(self, 'inferred_freq', None))
_, parsed, reso = parse_time_string(key, freq)
_, parsed, reso = parsing.parse_time_string(key, freq)
loc = self._partial_date_slice(reso, parsed, use_lhs=use_lhs,
use_rhs=use_rhs)
return loc
Expand Down Expand Up @@ -1965,8 +1964,8 @@ def indexer_between_time(self, start_time, end_time, include_start=True,
-------
values_between_time : TimeSeries
"""
start_time = to_time(start_time)
end_time = to_time(end_time)
start_time = tools.to_time(start_time)
end_time = tools.to_time(end_time)
time_micros = self._get_time_micros()
start_micros = _time_to_micros(start_time)
end_micros = _time_to_micros(end_time)
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,6 @@ def calc_with_mask(carg, mask):
return None


normalize_date = tslib.normalize_date

# Fixed time formats for time parsing
_time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
"%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"]
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pandas._libs import tslib
from pandas._libs.tslibs import parsing
from pandas.core.tools import datetimes as tools
from pandas.core.tools.datetimes import normalize_date

from pandas.compat import lmap
from pandas.compat.numpy import np_array_datetime64_compat
from pandas.core.dtypes.common import is_datetime64_ns_dtype
Expand Down Expand Up @@ -1576,12 +1576,12 @@ def test_coerce_of_invalid_datetimes(self):
def test_normalize_date():
value = date(2012, 9, 7)

result = normalize_date(value)
result = tslib.normalize_date(value)
assert (result == datetime(2012, 9, 7))

value = datetime(2012, 9, 7, 12)

result = normalize_date(value)
result = tslib.normalize_date(value)
assert (result == datetime(2012, 9, 7))


Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np

from pandas.core.dtypes.generic import ABCSeries, ABCDatetimeIndex, ABCPeriod
from pandas.core.tools.datetimes import to_datetime, normalize_date
from pandas.core.tools.datetimes import to_datetime
from pandas.core.common import AbstractMethodError

# import after tools, dateutil check
Expand Down Expand Up @@ -103,7 +103,7 @@ def wrapper(self, other):

if self.normalize:
# normalize_date returns normal datetime
result = normalize_date(result)
result = tslib.normalize_date(result)

if tz is not None and result.tzinfo is None:
result = tslib._localize_pydatetime(result, tz)
Expand Down