Skip to content

Commit abd0adf

Browse files
author
Kei
committed
Strip na values when inferring pyarrow dtype
1 parent 6f35c0e commit abd0adf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ def maybe_cast_to_pyarrow_dtype(result: ArrayLike, obj_dtype: Dtype) -> ArrayLik
503503

504504
from pandas.core.construction import array as pd_array
505505

506-
result[isna(result)] = np.nan
507-
if result.size == 0 or all(isna(result)):
506+
stripped_result = result[~isna(result)]
507+
if result.size == 0 or all(isna(stripped_result)):
508508
pandas_pyarrow_dtype = obj_dtype
509509
else:
510-
pyarrow_result = pa.array(result)
510+
pyarrow_result = pa.array(stripped_result)
511511
pandas_pyarrow_dtype = ArrowDtype(pyarrow_result.type)
512512

513513
result = pd_array(result, dtype=pandas_pyarrow_dtype)

0 commit comments

Comments
 (0)