xinrong-databricks commented on a change in pull request #33471:
URL: https://github.com/apache/spark/pull/33471#discussion_r675688102
##########
File path: python/pyspark/pandas/categorical.py
##########
@@ -442,8 +442,110 @@ def remove_categories(
def remove_unused_categories(self) -> "ps.Series":
raise NotImplementedError()
- def rename_categories(self, new_categories: pd.Index, inplace: bool =
False) -> "ps.Series":
- raise NotImplementedError()
+ def rename_categories(
+ self, new_categories: Union[list, dict, Callable], inplace: bool =
False
+ ) -> Optional["ps.Series"]:
+ """
+ Rename categories.
+
+ Parameters
+ ----------
+ new_categories : list-like, dict-like or callable
+
+ New categories which will replace old categories.
+
+ * list-like: all items must be unique and the number of items in
+ the new categories must match the existing number of categories.
+
+ * dict-like: specifies a mapping from
+ old categories to new. Categories not contained in the mapping
+ are passed through and extra categories in the mapping are
+ ignored.
+
+ * callable : a callable that is called on all items in the old
+ categories and whose return values comprise the new categories.
+
+ inplace : bool, default False
+ Whether or not to rename the categories inplace or return a copy of
+ this categorical with renamed categories.
Review comment:
Good idea. `inplace` is deprecated in several methods in pandas 1.3.0.
We may adjust that together when we support pandas 1.3.0.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]