From ec9a3084dff0f005bf94d5ba7e2baa82971917fc Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:59:42 +0300 Subject: [PATCH 1/2] Improve docstring for some methods in categorical/categoricaldtype --- ci/code_checks.sh | 9 --------- pandas/core/arrays/categorical.py | 28 ++++++++++++++++++++++++++++ pandas/core/dtypes/dtypes.py | 8 ++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 0c4e6641444f1..fdadda248d45c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -70,15 +70,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then --format=actions \ -i ES01 `# For now it is ok if docstrings are missing the extended summary` \ -i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \ - -i "pandas.Categorical.__array__ SA01" \ - -i "pandas.Categorical.codes SA01" \ - -i "pandas.Categorical.dtype SA01" \ - -i "pandas.Categorical.from_codes SA01" \ - -i "pandas.Categorical.ordered SA01" \ - -i "pandas.CategoricalDtype.categories SA01" \ - -i "pandas.CategoricalDtype.ordered SA01" \ - -i "pandas.CategoricalIndex.codes SA01" \ - -i "pandas.CategoricalIndex.ordered SA01" \ -i "pandas.DataFrame.__dataframe__ SA01" \ -i "pandas.DataFrame.__iter__ SA01" \ -i "pandas.DataFrame.assign SA01" \ diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 416331a260e9f..aa261f6591a5a 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -517,6 +517,11 @@ def dtype(self) -> CategoricalDtype: """ The :class:`~pandas.api.types.CategoricalDtype` for this instance. + See Also + -------- + astype : Cast argument to a specified dtype. + CategoricalDtype : Type for categorical data. + Examples -------- >>> cat = pd.Categorical(["a", "b"], ordered=True) @@ -741,6 +746,11 @@ def from_codes( ------- Categorical + See Also + -------- + codes : The category codes of the categorical. + CategoricalIndex : An Index with an underlying ``Categorical``. + Examples -------- >>> dtype = pd.CategoricalDtype(["a", "b"], ordered=True) @@ -830,6 +840,12 @@ def ordered(self) -> Ordered: """ Whether the categories have an ordered relationship. + See Also + -------- + set_ordered : Set the ordered attribute. + as_ordered : Set the Categorical to be ordered. + as_unordered : Set the Categorical to be unordered. + Examples -------- For :class:`pandas.Series`: @@ -881,6 +897,11 @@ def codes(self) -> np.ndarray: ndarray[int] A non-writable view of the ``codes`` array. + See Also + -------- + Categorical.from_codes : Make a Categorical from codes. + CategoricalIndex : An Index with an underlying ``Categorical``. + Examples -------- For :class:`pandas.Categorical`: @@ -1661,6 +1682,9 @@ def __array__( """ The numpy array interface. + Users should not call this directly. Rather, it is invoked by + :func:`numpy.array` and :func:`numpy.asarray`. + Parameters ---------- dtype : np.dtype or None @@ -1676,6 +1700,10 @@ def __array__( if dtype==None (default), the same dtype as categorical.categories.dtype. + See Also + -------- + numpy.asarray : Convert input to numpy.ndarray. + Examples -------- diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index f94d32a3b8547..f4c9abc69af40 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -622,6 +622,10 @@ def categories(self) -> Index: """ An ``Index`` containing the unique categories allowed. + See Also + -------- + ordered : Whether the categories have an ordered relationship. + Examples -------- >>> cat_type = pd.CategoricalDtype(categories=["a", "b"], ordered=True) @@ -635,6 +639,10 @@ def ordered(self) -> Ordered: """ Whether the categories have an ordered relationship. + See Also + -------- + categories : An Index containing the unique categories allowed. + Examples -------- >>> cat_type = pd.CategoricalDtype(categories=["a", "b"], ordered=True) From 513ecdf96e9742d45852ca93c3083d497b558053 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:02:33 +0300 Subject: [PATCH 2/2] Remove cat.ordered --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5ed54e1503ad4..98a26f1d3ac2e 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -223,7 +223,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Series.cat.as_ordered PR01" \ -i "pandas.Series.cat.as_unordered PR01" \ -i "pandas.Series.cat.codes SA01" \ - -i "pandas.Series.cat.ordered SA01" \ -i "pandas.Series.cat.remove_categories PR01,PR02" \ -i "pandas.Series.cat.remove_unused_categories PR01" \ -i "pandas.Series.cat.rename_categories PR01,PR02" \