Skip to content

Commit 6c801a6

Browse files
committed
BUG: Handling NaN case before dtype conversion pandas-dev#40638
1 parent 3c3589b commit 6c801a6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pandas/core/arrays/numpy_.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,19 @@ def to_numpy( # type: ignore[override]
355355
copy: bool = False,
356356
na_value=lib.no_default,
357357
) -> np.ndarray:
358-
result = np.asarray(self._ndarray, dtype=dtype)
359358

360-
if (copy or na_value is not lib.no_default) and result is self._ndarray:
361-
result = result.copy()
359+
temp = self
362360

363361
if na_value is not lib.no_default:
364-
result[self.isna()] = na_value
362+
temp = self.fillna(None)
363+
364+
365+
366+
result = np.asarray(temp._ndarray, dtype=dtype)
367+
368+
if (copy or na_value is not lib.no_default) and result is temp._ndarray:
369+
result = result.copy()
370+
365371

366372
return result
367373

0 commit comments

Comments
 (0)