ueshin commented on a change in pull request #33009:
URL: https://github.com/apache/spark/pull/33009#discussion_r655836478
##########
File path: python/pyspark/pandas/data_type_ops/num_ops.py
##########
@@ -416,6 +409,29 @@ def pretty_name(self) -> str:
def isnull(self, index_ops: Union["Index", "Series"]) -> Union["Series",
"Index"]:
return index_ops._with_new_scol(index_ops.spark.column.isNull())
+ def astype(
+ self, index_ops: Union["Index", "Series"], dtype: Union[str, type,
Dtype]
+ ) -> Union["Index", "Series"]:
+ dtype, spark_type = pandas_on_spark_type(dtype)
+
+ if isinstance(dtype, CategoricalDtype):
+ return _as_categorical_type(index_ops, dtype, spark_type)
+ elif isinstance(spark_type, BooleanType):
+ 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(
+ index_ops.spark.column.cast(spark_type)
+ )
+ return index_ops._with_new_scol(
+ scol.alias(index_ops._internal.data_spark_column_names[0]),
+ field=InternalField(dtype=dtype),
+ )
Review comment:
I guess we can reuse `_as_bool_type` in `base.py` file?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]