Skip to content

Commit bd145c8

Browse files
jbrockmendeljreback
authored andcommitted
implement libmissing; untangles _libs dependencies (#18357)
1 parent 717c4a2 commit bd145c8

20 files changed

+416
-263
lines changed

pandas/_libs/algos.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ from libc.math cimport sqrt, fabs
3232
# this is our util.pxd
3333
from util cimport numeric, get_nat
3434

35-
cimport lib
36-
from pandas._libs import lib
35+
import missing
3736

3837
cdef int64_t iNaT = get_nat()
3938

pandas/_libs/algos_rank_helper.pxi.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average', ascending=True,
8383
nan_value = {{neg_nan_value}}
8484

8585
{{if dtype == 'object'}}
86-
mask = lib.isnaobj(values)
86+
mask = missing.isnaobj(values)
8787
{{elif dtype == 'float64'}}
8888
mask = np.isnan(values)
8989
{{elif dtype == 'int64'}}
@@ -259,7 +259,7 @@ def rank_2d_{{dtype}}(object in_arr, axis=0, ties_method='average',
259259
nan_value = {{neg_nan_value}}
260260

261261
{{if dtype == 'object'}}
262-
mask = lib.isnaobj2d(values)
262+
mask = missing.isnaobj2d(values)
263263
{{elif dtype == 'float64'}}
264264
mask = np.isnan(values)
265265
{{elif dtype == 'int64'}}

pandas/_libs/hashtable.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cdef extern from "numpy/npy_math.h":
4242
cimport cython
4343
cimport numpy as cnp
4444

45-
from pandas._libs.lib import checknull
45+
from missing cimport checknull
4646

4747
cnp.import_array()
4848
cnp.import_ufunc()

pandas/_libs/hashtable_class_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Template for each `dtype` helper function for hashtable
44
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
55
"""
66

7-
from lib cimport is_null_datetimelike
7+
from missing cimport is_null_datetimelike
88

99

1010
#----------------------------------------------------------------------

pandas/_libs/lib.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# prototypes for sharing
22

3-
cdef bint is_null_datetimelike(v)
43
cpdef bint is_period(val)

pandas/_libs/lib.pyx

+2-122
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ PyDateTime_IMPORT
5353

5454
from tslibs.np_datetime cimport get_timedelta64_value, get_datetime64_value
5555

56-
from tslib cimport _check_all_nulls
5756
from tslib import NaT, Timestamp, Timedelta, array_to_datetime
5857
from interval import Interval
58+
from missing cimport checknull
5959

6060
cdef int64_t NPY_NAT = util.get_nat()
6161

6262
cimport util
63-
from util cimport is_array, _checknull, _checknan
63+
from util cimport is_array, _checknull
6464

6565
from libc.math cimport sqrt, fabs
6666

@@ -112,54 +112,6 @@ def memory_usage_of_objects(ndarray[object, ndim=1] arr):
112112

113113

114114
# ----------------------------------------------------------------------
115-
# isnull / notnull related
116-
117-
cdef double INF = <double> np.inf
118-
cdef double NEGINF = -INF
119-
120-
121-
cpdef bint checknull(object val):
122-
if util.is_float_object(val) or util.is_complex_object(val):
123-
return val != val # and val != INF and val != NEGINF
124-
elif util.is_datetime64_object(val):
125-
return get_datetime64_value(val) == NPY_NAT
126-
elif val is NaT:
127-
return True
128-
elif util.is_timedelta64_object(val):
129-
return get_timedelta64_value(val) == NPY_NAT
130-
elif is_array(val):
131-
return False
132-
else:
133-
return _checknull(val)
134-
135-
136-
cpdef bint checknull_old(object val):
137-
if util.is_float_object(val) or util.is_complex_object(val):
138-
return val != val or val == INF or val == NEGINF
139-
elif util.is_datetime64_object(val):
140-
return get_datetime64_value(val) == NPY_NAT
141-
elif val is NaT:
142-
return True
143-
elif util.is_timedelta64_object(val):
144-
return get_timedelta64_value(val) == NPY_NAT
145-
elif is_array(val):
146-
return False
147-
else:
148-
return _checknull(val)
149-
150-
151-
cpdef bint isposinf_scalar(object val):
152-
if util.is_float_object(val) and val == INF:
153-
return True
154-
else:
155-
return False
156-
157-
158-
cpdef bint isneginf_scalar(object val):
159-
if util.is_float_object(val) and val == NEGINF:
160-
return True
161-
else:
162-
return False
163115

164116

165117
cpdef bint isscalar(object val):
@@ -212,78 +164,6 @@ def item_from_zerodim(object val):
212164
return util.unbox_if_zerodim(val)
213165

214166

215-
@cython.wraparound(False)
216-
@cython.boundscheck(False)
217-
def isnaobj(ndarray arr):
218-
cdef Py_ssize_t i, n
219-
cdef object val
220-
cdef ndarray[uint8_t] result
221-
222-
assert arr.ndim == 1, "'arr' must be 1-D."
223-
224-
n = len(arr)
225-
result = np.empty(n, dtype=np.uint8)
226-
for i from 0 <= i < n:
227-
val = arr[i]
228-
result[i] = _check_all_nulls(val)
229-
return result.view(np.bool_)
230-
231-
232-
@cython.wraparound(False)
233-
@cython.boundscheck(False)
234-
def isnaobj_old(ndarray arr):
235-
cdef Py_ssize_t i, n
236-
cdef object val
237-
cdef ndarray[uint8_t] result
238-
239-
assert arr.ndim == 1, "'arr' must be 1-D."
240-
241-
n = len(arr)
242-
result = np.zeros(n, dtype=np.uint8)
243-
for i from 0 <= i < n:
244-
val = arr[i]
245-
result[i] = val is NaT or util._checknull_old(val)
246-
return result.view(np.bool_)
247-
248-
249-
@cython.wraparound(False)
250-
@cython.boundscheck(False)
251-
def isnaobj2d(ndarray arr):
252-
cdef Py_ssize_t i, j, n, m
253-
cdef object val
254-
cdef ndarray[uint8_t, ndim=2] result
255-
256-
assert arr.ndim == 2, "'arr' must be 2-D."
257-
258-
n, m = (<object> arr).shape
259-
result = np.zeros((n, m), dtype=np.uint8)
260-
for i from 0 <= i < n:
261-
for j from 0 <= j < m:
262-
val = arr[i, j]
263-
if checknull(val):
264-
result[i, j] = 1
265-
return result.view(np.bool_)
266-
267-
268-
@cython.wraparound(False)
269-
@cython.boundscheck(False)
270-
def isnaobj2d_old(ndarray arr):
271-
cdef Py_ssize_t i, j, n, m
272-
cdef object val
273-
cdef ndarray[uint8_t, ndim=2] result
274-
275-
assert arr.ndim == 2, "'arr' must be 2-D."
276-
277-
n, m = (<object> arr).shape
278-
result = np.zeros((n, m), dtype=np.uint8)
279-
for i from 0 <= i < n:
280-
for j from 0 <= j < m:
281-
val = arr[i, j]
282-
if checknull_old(val):
283-
result[i, j] = 1
284-
return result.view(np.bool_)
285-
286-
287167
@cython.wraparound(False)
288168
@cython.boundscheck(False)
289169
cpdef ndarray[object] list_to_object_array(list obj):

pandas/_libs/missing.pxd

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# cython: profile=False
3+
4+
cdef bint is_null_datetimelike(object val)
5+
cpdef bint checknull(object val)
6+
cpdef bint checknull_old(object val)

0 commit comments

Comments
 (0)