xinrong-databricks commented on a change in pull request #32847:
URL: https://github.com/apache/spark/pull/32847#discussion_r650263770
##########
File path: python/pyspark/pandas/data_type_ops/binary_ops.py
##########
@@ -53,3 +57,34 @@ def radd(self, left, right) -> Union["Series", "Index"]:
raise TypeError(
"Concatenation can not be applied to %s and the given type." %
self.pretty_name
)
+
+ 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 not spark_type:
+ raise ValueError("Type {} not understood".format(dtype))
Review comment:
Good catch, updated.
##########
File path: python/pyspark/pandas/data_type_ops/base.py
##########
@@ -39,9 +41,8 @@
TimestampType,
UserDefinedType,
)
-
import pyspark.sql.types as types
Review comment:
Makes sense, adjusted.
##########
File path: python/pyspark/pandas/tests/data_type_ops/test_binary_ops.py
##########
@@ -147,6 +147,14 @@ def test_from_to_pandas(self):
self.assert_eq(pser, psser.to_pandas())
self.assert_eq(ps.from_pandas(pser), psser)
+ def test_astype(self):
+ pser = self.pser
+ psser = self.psser
+ self.assert_eq(pd.Series(["1", "2", "3"]), psser.astype(str))
+ self.assert_eq(pser.astype("category"), psser.astype("category"))
+ cat_type = pd.api.types.CategoricalDtype(categories=[b"2", b"3", b"1"])
Review comment:
Certainly.
--
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]