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 02:42:35 UTC

[GitHub] [spark] Yikun opened a new pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Yikun opened a new pull request #33009:
URL: https://github.com/apache/spark/pull/33009


   ### What changes were proposed in this pull request?
   Make DecimalOps astype data-type-based.
   
   See more in:
   https://github.com/apache/spark/pull/32821#issuecomment-861119905
   
   
   ### Why are the changes needed?
   Make DecimalOps astype data-type-based.
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   Existing test NumOpsTest.test_astype in pyspark/pandas/tests/data_type_ops/test_num_ops.py 
   


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865653720


   **[Test build #140121 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140121/testReport)** for PR 33009 at commit [`3b5c507`](https://github.com/apache/spark/commit/3b5c5077f00e349db101d60d91b68f13613bf9a8).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds the following public classes _(experimental)_:
     * `class SparkIndexOpsMethods(Generic[T_IndexOps], metaclass=ABCMeta):`
     * `class SparkSeriesMethods(SparkIndexOpsMethods[\"ps.Series\"]):`
     * `class SparkIndexMethods(SparkIndexOpsMethods[\"ps.Index\"]):`
     * `case class GetTimestampWithoutTZ(`
     * `case class ParseToTimestampWithoutTZ(`


-- 
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


[GitHub] [spark] ueshin commented on a change in pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865511986


   **[Test build #140116 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140116/testReport)** for PR 33009 at commit [`04c53c4`](https://github.com/apache/spark/commit/04c53c41a623a3814ad1199201b038b12d905693).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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


[GitHub] [spark] Yikun commented on a change in pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [spark] ueshin closed pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
ueshin closed pull request #33009:
URL: https://github.com/apache/spark/pull/33009


   


-- 
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


[GitHub] [spark] SparkQA removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484388


   **[Test build #140114 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140114/testReport)** for PR 33009 at commit [`72d4c91`](https://github.com/apache/spark/commit/72d4c91847d6882977b0cc2573640ac4dafb1166).


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865636289


   **[Test build #140121 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140121/testReport)** for PR 33009 at commit [`3b5c507`](https://github.com/apache/spark/commit/3b5c5077f00e349db101d60d91b68f13613bf9a8).


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865669511


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44648/
   


-- 
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


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865519742


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44644/
   


-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499149


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140114/
   


-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865503989


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44642/
   


-- 
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


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865668419


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140121/
   


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865503985


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44642/
   


-- 
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


[GitHub] [spark] SparkQA removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484388






-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865668419


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140121/
   


-- 
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


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865503989


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44642/
   


-- 
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


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865518195


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140116/
   


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865495226


   **[Test build #140114 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140114/testReport)** for PR 33009 at commit [`72d4c91`](https://github.com/apache/spark/commit/72d4c91847d6882977b0cc2573640ac4dafb1166).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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


[GitHub] [spark] SparkQA removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499632


   **[Test build #140116 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140116/testReport)** for PR 33009 at commit [`04c53c4`](https://github.com/apache/spark/commit/04c53c41a623a3814ad1199201b038b12d905693).


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484388






-- 
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


[GitHub] [spark] xinrong-databricks commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-866250058


   Thanks @Yikun !


-- 
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


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499149


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140114/
   


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865516153


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44644/
   


-- 
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


[GitHub] [spark] Yikun commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
Yikun commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484219


   cc @xinrong-databricks @ueshin 


-- 
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


[GitHub] [spark] ueshin commented on a change in pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499149






-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865519722


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44644/
   


-- 
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


[GitHub] [spark] Yikun commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
Yikun commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484219


   cc @xinrong-databricks @ueshin 


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865500856


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44642/
   


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865484388


   **[Test build #140114 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140114/testReport)** for PR 33009 at commit [`72d4c91`](https://github.com/apache/spark/commit/72d4c91847d6882977b0cc2573640ac4dafb1166).


-- 
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


[GitHub] [spark] SparkQA commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499632


   **[Test build #140116 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140116/testReport)** for PR 33009 at commit [`04c53c4`](https://github.com/apache/spark/commit/04c53c41a623a3814ad1199201b038b12d905693).


-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865499149






-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865519742


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44644/
   


-- 
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


[GitHub] [spark] ueshin commented on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
ueshin commented on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-866194022


   Thanks! merging to master.


-- 
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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865518195


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/140116/
   


-- 
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


[GitHub] [spark] Yikun commented on a change in pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [spark] SparkQA removed a comment on pull request #33009: [SPARK-35849][PYTHON] Make `astype` method data-type-based for DecimalOps

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #33009:
URL: https://github.com/apache/spark/pull/33009#issuecomment-865636289


   **[Test build #140121 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/140121/testReport)** for PR 33009 at commit [`3b5c507`](https://github.com/apache/spark/commit/3b5c5077f00e349db101d60d91b68f13613bf9a8).


-- 
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