Skip to content

Commit ff8ecd1

Browse files
committed
PERF: make all inference routines cpdef bint
1 parent 5faf32a commit ff8ecd1

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
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

+24-26
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,31 @@ from util cimport (UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX,
1414
# core.common import for fast inference checks
1515

1616

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

2020

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

2424

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

2828

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

3232

33-
def is_decimal(object obj):
33+
cpdef bint is_decimal(object obj):
3434
return isinstance(obj, Decimal)
3535

36+
3637
cpdef bint is_period(object val):
3738
""" Return a boolean if this is a Period object """
3839
return util.is_period_object(val)
3940

41+
4042
_TYPE_MAP = {
4143
'categorical': 'categorical',
4244
'category': 'categorical',
@@ -234,7 +236,7 @@ def infer_dtype(object _values):
234236
return 'mixed'
235237

236238

237-
def is_possible_datetimelike_array(object arr):
239+
cpdef bint is_possible_datetimelike_array(object arr):
238240
# determine if we have a possible datetimelike (or null-like) array
239241
cdef:
240242
Py_ssize_t i, n = len(arr)
@@ -319,7 +321,7 @@ cdef inline bint is_timedelta(object o):
319321
return PyDelta_Check(o) or util.is_timedelta64_object(o)
320322

321323

322-
def is_bool_array(ndarray values):
324+
cpdef bint is_bool_array(ndarray values):
323325
cdef:
324326
Py_ssize_t i, n = len(values)
325327
ndarray[object] objbuf
@@ -340,11 +342,7 @@ def is_bool_array(ndarray values):
340342
return False
341343

342344

343-
def is_integer(object o):
344-
return util.is_integer_object(o)
345-
346-
347-
def is_integer_array(ndarray values):
345+
cpdef bint is_integer_array(ndarray values):
348346
cdef:
349347
Py_ssize_t i, n = len(values)
350348
ndarray[object] objbuf
@@ -365,7 +363,7 @@ def is_integer_array(ndarray values):
365363
return False
366364

367365

368-
def is_integer_float_array(ndarray values):
366+
cpdef bint is_integer_float_array(ndarray values):
369367
cdef:
370368
Py_ssize_t i, n = len(values)
371369
ndarray[object] objbuf
@@ -388,7 +386,7 @@ def is_integer_float_array(ndarray values):
388386
return False
389387

390388

391-
def is_float_array(ndarray values):
389+
cpdef bint is_float_array(ndarray values):
392390
cdef:
393391
Py_ssize_t i, n = len(values)
394392
ndarray[object] objbuf
@@ -409,7 +407,7 @@ def is_float_array(ndarray values):
409407
return False
410408

411409

412-
def is_string_array(ndarray values):
410+
cpdef bint is_string_array(ndarray values):
413411
cdef:
414412
Py_ssize_t i, n = len(values)
415413
ndarray[object] objbuf
@@ -431,7 +429,7 @@ def is_string_array(ndarray values):
431429
return False
432430

433431

434-
def is_unicode_array(ndarray values):
432+
cpdef bint is_unicode_array(ndarray values):
435433
cdef:
436434
Py_ssize_t i, n = len(values)
437435
ndarray[object] objbuf
@@ -452,7 +450,7 @@ def is_unicode_array(ndarray values):
452450
return False
453451

454452

455-
def is_bytes_array(ndarray values):
453+
cpdef bint is_bytes_array(ndarray values):
456454
cdef:
457455
Py_ssize_t i, n = len(values)
458456
ndarray[object] objbuf
@@ -473,7 +471,7 @@ def is_bytes_array(ndarray values):
473471
return False
474472

475473

476-
def is_datetime_array(ndarray[object] values):
474+
cpdef bint is_datetime_array(ndarray[object] values):
477475
cdef Py_ssize_t i, null_count = 0, n = len(values)
478476
cdef object v
479477
if n == 0:
@@ -491,7 +489,7 @@ def is_datetime_array(ndarray[object] values):
491489
return null_count != n
492490

493491

494-
def is_datetime64_array(ndarray values):
492+
cpdef bint is_datetime64_array(ndarray values):
495493
cdef Py_ssize_t i, null_count = 0, n = len(values)
496494
cdef object v
497495
if n == 0:
@@ -509,7 +507,7 @@ def is_datetime64_array(ndarray values):
509507
return null_count != n
510508

511509

512-
cpdef is_datetime_with_singletz_array(ndarray[object] values):
510+
cpdef bint is_datetime_with_singletz_array(ndarray[object] values):
513511
"""
514512
Check values have the same tzinfo attribute.
515513
Doesn't check values are datetime-like types.
@@ -537,7 +535,7 @@ cpdef is_datetime_with_singletz_array(ndarray[object] values):
537535
return True
538536

539537

540-
def is_timedelta_array(ndarray values):
538+
cpdef bint is_timedelta_array(ndarray values):
541539
cdef Py_ssize_t i, null_count = 0, n = len(values)
542540
cdef object v
543541
if n == 0:
@@ -553,7 +551,7 @@ def is_timedelta_array(ndarray values):
553551
return null_count != n
554552

555553

556-
def is_timedelta64_array(ndarray values):
554+
cpdef bint is_timedelta64_array(ndarray values):
557555
cdef Py_ssize_t i, null_count = 0, n = len(values)
558556
cdef object v
559557
if n == 0:
@@ -569,7 +567,7 @@ def is_timedelta64_array(ndarray values):
569567
return null_count != n
570568

571569

572-
def is_timedelta_or_timedelta64_array(ndarray values):
570+
cpdef bint is_timedelta_or_timedelta64_array(ndarray values):
573571
""" infer with timedeltas and/or nat/none """
574572
cdef Py_ssize_t i, null_count = 0, n = len(values)
575573
cdef object v
@@ -586,7 +584,7 @@ def is_timedelta_or_timedelta64_array(ndarray values):
586584
return null_count != n
587585

588586

589-
def is_date_array(ndarray[object] values):
587+
cpdef bint is_date_array(ndarray[object] values):
590588
cdef Py_ssize_t i, n = len(values)
591589
if n == 0:
592590
return False
@@ -596,7 +594,7 @@ def is_date_array(ndarray[object] values):
596594
return True
597595

598596

599-
def is_time_array(ndarray[object] values):
597+
cpdef bint is_time_array(ndarray[object] values):
600598
cdef Py_ssize_t i, n = len(values)
601599
if n == 0:
602600
return False
@@ -606,7 +604,7 @@ def is_time_array(ndarray[object] values):
606604
return True
607605

608606

609-
def is_period_array(ndarray[object] values):
607+
cpdef bint is_period_array(ndarray[object] values):
610608
cdef Py_ssize_t i, null_count = 0, n = len(values)
611609
cdef object v
612610
if n == 0:

0 commit comments

Comments
 (0)