xinrong-databricks commented on a change in pull request #33471:
URL: https://github.com/apache/spark/pull/33471#discussion_r675049023
##########
File path: python/pyspark/pandas/indexes/category.py
##########
@@ -364,6 +364,76 @@ def __getattr__(self, item: str) -> Any:
return partial(property_or_func, self)
raise AttributeError("'CategoricalIndex' object has no attribute
'{}'".format(item))
+ def rename_categories(
+ self, new_categories: Union[list, dict, Callable], inplace: bool =
False
+ ) -> Optional["CategoricalIndex"]:
+ """
+ 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.
+
+ Returns
+ -------
+ cat : CategoricalIndex or None
+ Categorical with removed categories or None if ``inplace=True``.
+
+ Raises
+ ------
+ ValueError
+ If new categories are list-like and do not have the same number of
+ items than the current categories or do not validate as categories
+
+ See Also
+ --------
+ reorder_categories : Reorder categories.
+ add_categories : Add new categories.
+ remove_categories : Remove the specified categories.
+ remove_unused_categories : Remove categories which are not used.
+ set_categories : Set the categories to the specified ones.
+
+ Examples
+ --------
+ >>> psser = ps.CategoricalIndex(["a", "a", "b"])
Review comment:
Updated.
--
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]