diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 2f95367266a36..95afdcbd3ccc4 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -82,7 +82,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.RangeIndex.start SA01" \ -i "pandas.RangeIndex.step SA01" \ -i "pandas.RangeIndex.stop SA01" \ - -i "pandas.Series.cat.add_categories PR01,PR02" \ -i "pandas.Series.cat.as_ordered PR01" \ -i "pandas.Series.cat.as_unordered PR01" \ -i "pandas.Series.cat.remove_categories PR01,PR02" \ diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index c613a345686cc..457eb58533bc0 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1302,11 +1302,25 @@ def add_categories(self, new_categories) -> Self: """ Add new categories. - `new_categories` will be included at the last/highest place in the - categories and will be unused directly after this call. + `new_categories` will be included at the last/highest place in the categories + and will be unused directly after this call. This method is useful when + working with categorical data that needs to be updated or extended with new + categories over time. Adding categories in this way avoids the need to + redefine the entire set of categories, which can be especially helpful in + scenarios where the categorical data is large or frequently updated. New + categories are added to the end of the list of categories, and their presence + will not affect the current categorical values directly until they are + explicitly used. Parameters ---------- + *args : iterable, optional + Positional arguments passed into `func`. + **kwargs : dict, optional + A dictionary of keyword arguments passed into `func`. + + Attributes + ---------- new_categories : category or list-like of category The new categories to be included.