Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyspark/pandas/data_type_ops/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _as_bool_type(index_ops: IndexOpsLike, dtype: Dtype) -> IndexOpsLike:
if isinstance(dtype, extension_dtypes):
scol = index_ops.spark.column.cast(spark_type)
else:
scol = F.when(index_ops.spark.column.isNull(), F.lit(False)).otherwise(
scol = F.when(index_ops.spark.column.isNull(), F.lit(True)).otherwise(
index_ops.spark.column.cast(spark_type)
)
return index_ops._with_new_scol(
Expand Down
5 changes: 1 addition & 4 deletions python/pyspark/pandas/tests/data_type_ops/test_as_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ def test_astype(self):
lambda: psser.astype(int_type),
)

# TODO(SPARK-37039): the np.nan series.astype(bool) should be True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add this into migration guide though.

if not pser.hasnans:
self.assert_eq(pser.astype(bool), psser.astype(bool))

self.assert_eq(pser.astype(bool), psser.astype(bool))
self.assert_eq(pser.astype(float), psser.astype(float))
self.assert_eq(pser.astype(np.float32), psser.astype(np.float32))
self.assert_eq(pser.astype(str), psser.astype(str))
Expand Down