xinrong-databricks commented on a change in pull request #32592:
URL: https://github.com/apache/spark/pull/32592#discussion_r645748876
##########
File path: python/pyspark/pandas/data_type_ops/categorical_ops.py
##########
@@ -26,3 +29,13 @@ class CategoricalOps(DataTypeOps):
@property
def pretty_name(self) -> str:
return 'categoricals'
+
+ def restore(self, col):
+ """Restore column when to_pandas."""
+ return pd.Categorical.from_codes(
+ col, categories=self.dtype.categories, ordered=self.dtype.ordered
+ )
+
+ def prepare(self, col):
+ """Prepare column when from_pandas."""
+ return col.cat.codes.replace({np.nan: None})
Review comment:
Good point!
--
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]