Skip to content

Commit edb26d7

Browse files
BUG: np.nan stays as np.nan (pandas-dev#20377)
1 parent 478d08d commit edb26d7

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

pandas/_libs/lib.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
466466
# we can use the unsafe version because we know `result` is mutable
467467
# since it was created from `np.empty`
468468
arr_i = arr[i]
469-
util.set_value_at_unsafe(result, i, unicode(arr_i) if arr_i is not np.nan else '')
469+
util.set_value_at_unsafe(result, i, unicode(arr_i) if arr_i is not np.nan else np.nan)
470470

471471
return result
472472

@@ -480,7 +480,7 @@ cpdef ndarray[object] astype_str(ndarray arr):
480480
# we can use the unsafe version because we know `result` is mutable
481481
# since it was created from `np.empty`
482482
arr_i = arr[i]
483-
util.set_value_at_unsafe(result, i, str(arr_i) if arr_i is not np.nan else '')
483+
util.set_value_at_unsafe(result, i, str(arr_i) if arr_i is not np.nan else np.nan)
484484

485485
return result
486486

pandas/_libs/parsers.pyx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,8 @@ cdef class TextReader:
12161216
return result, 0
12171217

12181218
# treat as a regular string parsing
1219-
res, na_count = self._string_convert(i, start, end, na_filter,
1220-
na_hashset)
1221-
1222-
for i in range(len(res)):
1223-
if res[i] is np.nan:
1224-
res[i] = ''
1225-
return res, na_count
1219+
return self._string_convert(i, start, end, na_filter,
1220+
na_hashset)
12261221

12271222
elif dtype.kind == 'U':
12281223
width = dtype.itemsize
@@ -1231,12 +1226,8 @@ cdef class TextReader:
12311226
"supported for parsing" % dtype)
12321227

12331228
# unicode variable width
1234-
res, na_count = self._string_convert(i, start, end, na_filter,
1235-
na_hashset)
1236-
for i in range(len(res)):
1237-
if res[i] is np.nan:
1238-
res[i] = ''
1239-
return res, na_count
1229+
return self._string_convert(i, start, end, na_filter,
1230+
na_hashset)
12401231

12411232
elif is_categorical_dtype(dtype):
12421233
# TODO: I suspect that _categorical_convert could be

0 commit comments

Comments
 (0)