Skip to content

Commit eb07104

Browse files
committed
PERF: make all inference routines cpdef bint
1 parent 8e630b6 commit eb07104

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

pandas/lib.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ cdef double INF = <double> np.inf
257257
cdef double NEGINF = -INF
258258

259259

260-
cpdef checknull(object val):
260+
cpdef bint checknull(object val):
261261
if util.is_float_object(val) or util.is_complex_object(val):
262262
return val != val # and val != INF and val != NEGINF
263263
elif util.is_datetime64_object(val):
@@ -272,7 +272,7 @@ cpdef checknull(object val):
272272
return _checknull(val)
273273

274274

275-
cpdef checknull_old(object val):
275+
cpdef bint checknull_old(object val):
276276
if util.is_float_object(val) or util.is_complex_object(val):
277277
return val != val or val == INF or val == NEGINF
278278
elif util.is_datetime64_object(val):
@@ -287,21 +287,21 @@ cpdef checknull_old(object val):
287287
return util._checknull(val)
288288

289289

290-
cpdef isposinf_scalar(object val):
290+
cpdef bint isposinf_scalar(object val):
291291
if util.is_float_object(val) and val == INF:
292292
return True
293293
else:
294294
return False
295295

296296

297-
cpdef isneginf_scalar(object val):
297+
cpdef bint isneginf_scalar(object val):
298298
if util.is_float_object(val) and val == NEGINF:
299299
return True
300300
else:
301301
return False
302302

303303

304-
def isscalar(object val):
304+
cpdef bint isscalar(object val):
305305
"""
306306
Return True if given value is scalar.
307307

pandas/src/inference.pyx

+21-25
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ from util cimport (UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX,
1313
# core.common import for fast inference checks
1414

1515

16-
def is_float(object obj):
16+
cpdef bint is_float(object obj):
1717
return util.is_float_object(obj)
1818

1919

20-
def is_integer(object obj):
20+
cpdef bint is_integer(object obj):
2121
return util.is_integer_object(obj)
2222

2323

24-
def is_bool(object obj):
24+
cpdef bint is_bool(object obj):
2525
return util.is_bool_object(obj)
2626

2727

28-
def is_complex(object obj):
28+
cpdef bint is_complex(object obj):
2929
return util.is_complex_object(obj)
3030

3131
cpdef bint is_period(object val):
@@ -229,7 +229,7 @@ def infer_dtype(object _values):
229229
return 'mixed'
230230

231231

232-
def is_possible_datetimelike_array(object arr):
232+
cpdef bint is_possible_datetimelike_array(object arr):
233233
# determine if we have a possible datetimelike (or null-like) array
234234
cdef:
235235
Py_ssize_t i, n = len(arr)
@@ -314,7 +314,7 @@ cdef inline bint is_timedelta(object o):
314314
return PyDelta_Check(o) or util.is_timedelta64_object(o)
315315

316316

317-
def is_bool_array(ndarray values):
317+
cpdef bint is_bool_array(ndarray values):
318318
cdef:
319319
Py_ssize_t i, n = len(values)
320320
ndarray[object] objbuf
@@ -335,11 +335,7 @@ def is_bool_array(ndarray values):
335335
return False
336336

337337

338-
def is_integer(object o):
339-
return util.is_integer_object(o)
340-
341-
342-
def is_integer_array(ndarray values):
338+
cpdef bint is_integer_array(ndarray values):
343339
cdef:
344340
Py_ssize_t i, n = len(values)
345341
ndarray[object] objbuf
@@ -360,7 +356,7 @@ def is_integer_array(ndarray values):
360356
return False
361357

362358

363-
def is_integer_float_array(ndarray values):
359+
cpdef bint is_integer_float_array(ndarray values):
364360
cdef:
365361
Py_ssize_t i, n = len(values)
366362
ndarray[object] objbuf
@@ -383,7 +379,7 @@ def is_integer_float_array(ndarray values):
383379
return False
384380

385381

386-
def is_float_array(ndarray values):
382+
cpdef bint is_float_array(ndarray values):
387383
cdef:
388384
Py_ssize_t i, n = len(values)
389385
ndarray[object] objbuf
@@ -404,7 +400,7 @@ def is_float_array(ndarray values):
404400
return False
405401

406402

407-
def is_string_array(ndarray values):
403+
cpdef bint is_string_array(ndarray values):
408404
cdef:
409405
Py_ssize_t i, n = len(values)
410406
ndarray[object] objbuf
@@ -426,7 +422,7 @@ def is_string_array(ndarray values):
426422
return False
427423

428424

429-
def is_unicode_array(ndarray values):
425+
cpdef bint is_unicode_array(ndarray values):
430426
cdef:
431427
Py_ssize_t i, n = len(values)
432428
ndarray[object] objbuf
@@ -447,7 +443,7 @@ def is_unicode_array(ndarray values):
447443
return False
448444

449445

450-
def is_bytes_array(ndarray values):
446+
cpdef bint is_bytes_array(ndarray values):
451447
cdef:
452448
Py_ssize_t i, n = len(values)
453449
ndarray[object] objbuf
@@ -468,7 +464,7 @@ def is_bytes_array(ndarray values):
468464
return False
469465

470466

471-
def is_datetime_array(ndarray[object] values):
467+
cpdef bint is_datetime_array(ndarray[object] values):
472468
cdef Py_ssize_t i, null_count = 0, n = len(values)
473469
cdef object v
474470
if n == 0:
@@ -486,7 +482,7 @@ def is_datetime_array(ndarray[object] values):
486482
return null_count != n
487483

488484

489-
def is_datetime64_array(ndarray values):
485+
cpdef bint is_datetime64_array(ndarray values):
490486
cdef Py_ssize_t i, null_count = 0, n = len(values)
491487
cdef object v
492488
if n == 0:
@@ -504,7 +500,7 @@ def is_datetime64_array(ndarray values):
504500
return null_count != n
505501

506502

507-
cpdef is_datetime_with_singletz_array(ndarray[object] values):
503+
cpdef bint is_datetime_with_singletz_array(ndarray[object] values):
508504
"""
509505
Check values have the same tzinfo attribute.
510506
Doesn't check values are datetime-like types.
@@ -532,7 +528,7 @@ cpdef is_datetime_with_singletz_array(ndarray[object] values):
532528
return True
533529

534530

535-
def is_timedelta_array(ndarray values):
531+
cpdef bint is_timedelta_array(ndarray values):
536532
cdef Py_ssize_t i, null_count = 0, n = len(values)
537533
cdef object v
538534
if n == 0:
@@ -548,7 +544,7 @@ def is_timedelta_array(ndarray values):
548544
return null_count != n
549545

550546

551-
def is_timedelta64_array(ndarray values):
547+
cpdef bint is_timedelta64_array(ndarray values):
552548
cdef Py_ssize_t i, null_count = 0, n = len(values)
553549
cdef object v
554550
if n == 0:
@@ -564,7 +560,7 @@ def is_timedelta64_array(ndarray values):
564560
return null_count != n
565561

566562

567-
def is_timedelta_or_timedelta64_array(ndarray values):
563+
cpdef bint is_timedelta_or_timedelta64_array(ndarray values):
568564
""" infer with timedeltas and/or nat/none """
569565
cdef Py_ssize_t i, null_count = 0, n = len(values)
570566
cdef object v
@@ -581,7 +577,7 @@ def is_timedelta_or_timedelta64_array(ndarray values):
581577
return null_count != n
582578

583579

584-
def is_date_array(ndarray[object] values):
580+
cpdef bint is_date_array(ndarray[object] values):
585581
cdef Py_ssize_t i, n = len(values)
586582
if n == 0:
587583
return False
@@ -591,7 +587,7 @@ def is_date_array(ndarray[object] values):
591587
return True
592588

593589

594-
def is_time_array(ndarray[object] values):
590+
cpdef bint is_time_array(ndarray[object] values):
595591
cdef Py_ssize_t i, n = len(values)
596592
if n == 0:
597593
return False
@@ -601,7 +597,7 @@ def is_time_array(ndarray[object] values):
601597
return True
602598

603599

604-
def is_period_array(ndarray[object] values):
600+
cpdef bint is_period_array(ndarray[object] values):
605601
cdef Py_ssize_t i, null_count = 0, n = len(values)
606602
cdef object v
607603
if n == 0:

0 commit comments

Comments
 (0)