Skip to content

Commit e99cb9c

Browse files
jbrockmendeljreback
authored andcommitted
Update imports, use nogil version of sqrt (#18557)
1 parent 02e72ec commit e99cb9c

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

Diff for: pandas/_libs/algos.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from numpy cimport (ndarray,
2727
cdef double NaN = <double> np.NaN
2828
cdef double nan = NaN
2929

30-
from libc.math cimport sqrt, fabs
30+
from libc.math cimport fabs, sqrt
3131

3232
# this is our util.pxd
3333
from util cimport numeric, get_nat

Diff for: pandas/_libs/lib.pyx

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# cython: profile=False
2-
cimport numpy as np
3-
cimport cython
4-
import numpy as np
5-
import sys
2+
import operator
63

7-
cdef bint PY3 = (sys.version_info[0] >= 3)
8-
9-
from numpy cimport *
4+
cimport cython
5+
from cython cimport Py_ssize_t
106

7+
import numpy as np
8+
cimport numpy as np
9+
from numpy cimport (ndarray, PyArray_NDIM, PyArray_GETITEM, PyArray_SETITEM,
10+
PyArray_ITER_DATA, PyArray_ITER_NEXT, PyArray_IterNew,
11+
flatiter, NPY_OBJECT,
12+
int64_t,
13+
float32_t, float64_t,
14+
uint8_t, uint64_t,
15+
complex128_t)
1116
# initialize numpy
1217
np.import_array()
1318
np.import_ufunc()
@@ -57,12 +62,12 @@ from tslib import NaT, Timestamp, Timedelta, array_to_datetime
5762
from interval import Interval
5863
from missing cimport checknull
5964

60-
cdef int64_t NPY_NAT = util.get_nat()
6165

6266
cimport util
67+
cdef int64_t NPY_NAT = util.get_nat()
6368
from util cimport is_array, _checknull
6469

65-
from libc.math cimport sqrt, fabs
70+
from libc.math cimport fabs, sqrt
6671

6772

6873
def values_from_object(object o):
@@ -494,7 +499,6 @@ def maybe_booleans_to_slice(ndarray[uint8_t] mask):
494499
@cython.wraparound(False)
495500
@cython.boundscheck(False)
496501
def scalar_compare(ndarray[object] values, object val, object op):
497-
import operator
498502
cdef:
499503
Py_ssize_t i, n = len(values)
500504
ndarray[uint8_t, cast=True] result
@@ -529,7 +533,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
529533
result[i] = True
530534
else:
531535
try:
532-
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
536+
result[i] = PyObject_RichCompareBool(x, val, flag)
533537
except (TypeError):
534538
result[i] = True
535539
elif flag == cpython.Py_EQ:
@@ -541,7 +545,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
541545
result[i] = False
542546
else:
543547
try:
544-
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
548+
result[i] = PyObject_RichCompareBool(x, val, flag)
545549
except (TypeError):
546550
result[i] = False
547551

@@ -553,7 +557,7 @@ def scalar_compare(ndarray[object] values, object val, object op):
553557
elif isnull_val:
554558
result[i] = False
555559
else:
556-
result[i] = cpython.PyObject_RichCompareBool(x, val, flag)
560+
result[i] = PyObject_RichCompareBool(x, val, flag)
557561

558562
return result.view(bool)
559563

@@ -582,7 +586,6 @@ cpdef bint array_equivalent_object(object[:] left, object[:] right):
582586
@cython.wraparound(False)
583587
@cython.boundscheck(False)
584588
def vec_compare(ndarray[object] left, ndarray[object] right, object op):
585-
import operator
586589
cdef:
587590
Py_ssize_t i, n = len(left)
588591
ndarray[uint8_t, cast=True] result
@@ -617,7 +620,7 @@ def vec_compare(ndarray[object] left, ndarray[object] right, object op):
617620
if checknull(x) or checknull(y):
618621
result[i] = True
619622
else:
620-
result[i] = cpython.PyObject_RichCompareBool(x, y, flag)
623+
result[i] = PyObject_RichCompareBool(x, y, flag)
621624
else:
622625
for i in range(n):
623626
x = left[i]
@@ -626,7 +629,7 @@ def vec_compare(ndarray[object] left, ndarray[object] right, object op):
626629
if checknull(x) or checknull(y):
627630
result[i] = False
628631
else:
629-
result[i] = cpython.PyObject_RichCompareBool(x, y, flag)
632+
result[i] = PyObject_RichCompareBool(x, y, flag)
630633

631634
return result.view(bool)
632635

Diff for: pandas/_libs/src/util.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from numpy cimport ndarray
22
cimport numpy as cnp
33
cimport cpython
44

5+
56
cdef extern from "numpy_helper.h":
67
void set_array_not_contiguous(ndarray ao)
78

Diff for: pandas/core/indexes/datetimes.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin)
4444
from pandas.tseries.offsets import (
4545
DateOffset, generate_range, Tick, CDay, prefix_mapping)
46-
from pandas.core.tools.datetimes import (
47-
parse_time_string, normalize_date, to_time)
46+
4847
from pandas.core.tools.timedeltas import to_timedelta
4948
from pandas.util._decorators import (Appender, cache_readonly,
5049
deprecate_kwarg, Substitution)
@@ -55,7 +54,7 @@
5554
from pandas._libs import (lib, index as libindex, tslib as libts,
5655
algos as libalgos, join as libjoin,
5756
Timestamp)
58-
from pandas._libs.tslibs import (timezones, conversion, fields,
57+
from pandas._libs.tslibs import (timezones, conversion, fields, parsing,
5958
period as libperiod)
6059

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

525524
if start is not None:
526525
if normalize:
527-
start = normalize_date(start)
526+
start = libts.normalize_date(start)
528527
_normalized = True
529528
else:
530529
_normalized = _normalized and start.time() == _midnight
531530

532531
if end is not None:
533532
if normalize:
534-
end = normalize_date(end)
533+
end = libts.normalize_date(end)
535534
_normalized = True
536535
else:
537536
_normalized = _normalized and end.time() == _midnight
@@ -1529,7 +1528,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
15291528
if isinstance(label, compat.string_types):
15301529
freq = getattr(self, 'freqstr',
15311530
getattr(self, 'inferred_freq', None))
1532-
_, parsed, reso = parse_time_string(label, freq)
1531+
_, parsed, reso = parsing.parse_time_string(label, freq)
15331532
lower, upper = self._parsed_string_to_bounds(reso, parsed)
15341533
# lower, upper form the half-open interval:
15351534
# [parsed, parsed + 1 freq)
@@ -1546,7 +1545,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
15461545
def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
15471546
freq = getattr(self, 'freqstr',
15481547
getattr(self, 'inferred_freq', None))
1549-
_, parsed, reso = parse_time_string(key, freq)
1548+
_, parsed, reso = parsing.parse_time_string(key, freq)
15501549
loc = self._partial_date_slice(reso, parsed, use_lhs=use_lhs,
15511550
use_rhs=use_rhs)
15521551
return loc
@@ -1965,8 +1964,8 @@ def indexer_between_time(self, start_time, end_time, include_start=True,
19651964
-------
19661965
values_between_time : TimeSeries
19671966
"""
1968-
start_time = to_time(start_time)
1969-
end_time = to_time(end_time)
1967+
start_time = tools.to_time(start_time)
1968+
end_time = tools.to_time(end_time)
19701969
time_micros = self._get_time_micros()
19711970
start_micros = _time_to_micros(start_time)
19721971
end_micros = _time_to_micros(end_time)

Diff for: pandas/core/tools/datetimes.py

-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,6 @@ def calc_with_mask(carg, mask):
629629
return None
630630

631631

632-
normalize_date = tslib.normalize_date
633-
634632
# Fixed time formats for time parsing
635633
_time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
636634
"%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"]

Diff for: pandas/tests/indexes/datetimes/test_tools.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pandas._libs import tslib
1717
from pandas._libs.tslibs import parsing
1818
from pandas.core.tools import datetimes as tools
19-
from pandas.core.tools.datetimes import normalize_date
19+
2020
from pandas.compat import lmap
2121
from pandas.compat.numpy import np_array_datetime64_compat
2222
from pandas.core.dtypes.common import is_datetime64_ns_dtype
@@ -1576,12 +1576,12 @@ def test_coerce_of_invalid_datetimes(self):
15761576
def test_normalize_date():
15771577
value = date(2012, 9, 7)
15781578

1579-
result = normalize_date(value)
1579+
result = tslib.normalize_date(value)
15801580
assert (result == datetime(2012, 9, 7))
15811581

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

1584-
result = normalize_date(value)
1584+
result = tslib.normalize_date(value)
15851585
assert (result == datetime(2012, 9, 7))
15861586

15871587

Diff for: pandas/tseries/offsets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010
from pandas.core.dtypes.generic import ABCSeries, ABCDatetimeIndex, ABCPeriod
11-
from pandas.core.tools.datetimes import to_datetime, normalize_date
11+
from pandas.core.tools.datetimes import to_datetime
1212
from pandas.core.common import AbstractMethodError
1313

1414
# import after tools, dateutil check
@@ -103,7 +103,7 @@ def wrapper(self, other):
103103

104104
if self.normalize:
105105
# normalize_date returns normal datetime
106-
result = normalize_date(result)
106+
result = tslib.normalize_date(result)
107107

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

0 commit comments

Comments
 (0)