Skip to content

Commit 3740dfe

Browse files
BUG: use checknull (pandas-dev#20377)
1 parent 47bc105 commit 3740dfe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/_libs/lib.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
461461
cdef:
462462
Py_ssize_t i, n = arr.size
463463
ndarray[object] result = np.empty(n, dtype=object)
464+
object arr_i
464465

465466
for i in range(n):
466467
# we can use the unsafe version because we know `result` is mutable
@@ -469,7 +470,8 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
469470
util.set_value_at_unsafe(
470471
result,
471472
i,
472-
unicode(arr_i) if arr_i is not np.nan else np.nan)
473+
unicode(arr_i) if not checknull(arr_i) else np.nan
474+
)
473475

474476
return result
475477

@@ -478,6 +480,7 @@ cpdef ndarray[object] astype_str(ndarray arr):
478480
cdef:
479481
Py_ssize_t i, n = arr.size
480482
ndarray[object] result = np.empty(n, dtype=object)
483+
object arr_i
481484

482485
for i in range(n):
483486
# we can use the unsafe version because we know `result` is mutable
@@ -486,7 +489,8 @@ cpdef ndarray[object] astype_str(ndarray arr):
486489
util.set_value_at_unsafe(
487490
result,
488491
i,
489-
str(arr_i) if arr_i is not np.nan else np.nan)
492+
str(arr_i) if not checknull(arr_i) else np.nan
493+
)
490494

491495
return result
492496

0 commit comments

Comments
 (0)