You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/22 03:26:15 UTC
[GitHub] [spark] Yikun commented on a change in pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps
Yikun commented on a change in pull request #33009:
URL: https://github.com/apache/spark/pull/33009#discussion_r655848483
##########
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:
yep
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org