Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 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,10 @@ 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(
null_value = (
F.lit(True) if isinstance(index_ops.spark.data_type, DecimalType) else F.lit(False)
)
scol = F.when(index_ops.spark.column.isNull(), null_value).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
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