Skip to content

Commit 5f4b905

Browse files
jbrockmendelrhshadrach
authored andcommitted
Move NA import out of nattype.pyx (pandas-dev#34009)
1 parent 61b57a7 commit 5f4b905

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

pandas/_libs/missing.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cpdef ndarray[uint8_t] isnaobj(ndarray arr)
66

77
cdef bint is_null_datetime64(v)
88
cdef bint is_null_timedelta64(v)
9+
cdef bint checknull_with_nat_and_na(object obj)
910

1011
cdef class C_NAType:
1112
pass

pandas/_libs/missing.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ cdef inline bint is_null_timedelta64(v):
279279
return False
280280

281281

282+
cdef bint checknull_with_nat_and_na(object obj):
283+
# See GH#32214
284+
return checknull_with_nat(obj) or obj is C_NA
285+
286+
282287
# -----------------------------------------------------------------------------
283288
# Implementation of NA singleton
284289

pandas/_libs/tslib.pyx

+9-7
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ from pandas._libs.tslibs.conversion cimport (
5151
get_datetime64_nanos)
5252

5353
from pandas._libs.tslibs.nattype import nat_strings
54-
from pandas._libs.tslibs.nattype cimport (
55-
checknull_with_nat, NPY_NAT, c_NaT as NaT)
54+
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
5655

5756
from pandas._libs.tslibs.offsets cimport to_offset
5857

@@ -64,6 +63,9 @@ from pandas._libs.tslibs.tzconversion cimport (
6463
tz_convert_utc_to_tzlocal,
6564
)
6665

66+
# Note: this is the only non-tslibs intra-pandas dependency here
67+
from pandas._libs.missing cimport checknull_with_nat_and_na
68+
6769

6870
cdef inline object create_datetime_from_ts(
6971
int64_t value,
@@ -438,7 +440,7 @@ def array_with_unit_to_datetime(
438440
for i in range(n):
439441
val = values[i]
440442

441-
if checknull_with_nat(val):
443+
if checknull_with_nat_and_na(val):
442444
iresult[i] = NPY_NAT
443445

444446
elif is_integer_object(val) or is_float_object(val):
@@ -505,7 +507,7 @@ def array_with_unit_to_datetime(
505507
for i in range(n):
506508
val = values[i]
507509

508-
if checknull_with_nat(val):
510+
if checknull_with_nat_and_na(val):
509511
oresult[i] = <object>NaT
510512
elif is_integer_object(val) or is_float_object(val):
511513

@@ -602,7 +604,7 @@ cpdef array_to_datetime(
602604
val = values[i]
603605

604606
try:
605-
if checknull_with_nat(val):
607+
if checknull_with_nat_and_na(val):
606608
iresult[i] = NPY_NAT
607609

608610
elif PyDateTime_Check(val):
@@ -812,7 +814,7 @@ cdef ignore_errors_out_of_bounds_fallback(ndarray[object] values):
812814
val = values[i]
813815

814816
# set as nan except if its a NaT
815-
if checknull_with_nat(val):
817+
if checknull_with_nat_and_na(val):
816818
if isinstance(val, float):
817819
oresult[i] = np.nan
818820
else:
@@ -874,7 +876,7 @@ cdef array_to_datetime_object(
874876
# 2) datetime strings, which we return as datetime.datetime
875877
for i in range(n):
876878
val = values[i]
877-
if checknull_with_nat(val) or PyDateTime_Check(val):
879+
if checknull_with_nat_and_na(val) or PyDateTime_Check(val):
878880
# GH 25978. No need to parse NaT-like or datetime-like vals
879881
oresult[i] = val
880882
elif isinstance(val, str):

pandas/_libs/tslibs/nattype.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ from pandas._libs.tslibs.np_datetime cimport (
3131
cimport pandas._libs.tslibs.util as util
3232
from pandas._libs.tslibs.base cimport is_period_object
3333

34-
from pandas._libs.missing cimport C_NA
35-
3634

3735
# ----------------------------------------------------------------------
3836
# Constants
@@ -809,7 +807,7 @@ cdef inline bint checknull_with_nat(object val):
809807
"""
810808
Utility to check if a value is a nat or not.
811809
"""
812-
return val is None or util.is_nan(val) or val is c_NaT or val is C_NA
810+
return val is None or util.is_nan(val) or val is c_NaT
813811

814812

815813
cpdef bint is_null_datetimelike(object val, bint inat_is_null=True):

0 commit comments

Comments
 (0)