Skip to content

Commit f94860e

Browse files
authored
DOC: Refactor _create_delegator_method using functools (#59878)
* add tag dt.to_timestamp, series.rst * add doc strings for dt.to_timestamp * update datetimes.py * refactor _create_delegator_method to use functools wrap * changes to accessor.py * remove from code_checks.sh * update code_checks.sh * update code_checks.sh * rewrite functools, adjust unit tests * update change log * remove dup entry * update code_checks.sh * update * revert all dt related changes * update series.rst * update imports * format use of functools import
1 parent 5ea5bd9 commit f94860e

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

ci/code_checks.sh

-20
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7373
-i "pandas.Period.freq GL08" \
7474
-i "pandas.Period.ordinal GL08" \
7575
-i "pandas.RangeIndex.from_range PR01,SA01" \
76-
-i "pandas.Series.cat.add_categories PR01,PR02" \
77-
-i "pandas.Series.cat.as_ordered PR01" \
78-
-i "pandas.Series.cat.as_unordered PR01" \
79-
-i "pandas.Series.cat.remove_categories PR01,PR02" \
80-
-i "pandas.Series.cat.remove_unused_categories PR01" \
81-
-i "pandas.Series.cat.rename_categories PR01,PR02" \
82-
-i "pandas.Series.cat.reorder_categories PR01,PR02" \
83-
-i "pandas.Series.cat.set_categories PR01,PR02" \
84-
-i "pandas.Series.dt.as_unit PR01,PR02" \
85-
-i "pandas.Series.dt.ceil PR01,PR02" \
86-
-i "pandas.Series.dt.day_name PR01,PR02" \
87-
-i "pandas.Series.dt.floor PR01,PR02" \
8876
-i "pandas.Series.dt.freq GL08" \
89-
-i "pandas.Series.dt.month_name PR01,PR02" \
90-
-i "pandas.Series.dt.normalize PR01" \
91-
-i "pandas.Series.dt.round PR01,PR02" \
92-
-i "pandas.Series.dt.strftime PR01,PR02" \
93-
-i "pandas.Series.dt.to_period PR01,PR02" \
94-
-i "pandas.Series.dt.total_seconds PR01" \
95-
-i "pandas.Series.dt.tz_convert PR01,PR02" \
96-
-i "pandas.Series.dt.tz_localize PR01,PR02" \
9777
-i "pandas.Series.dt.unit GL08" \
9878
-i "pandas.Series.pad PR01,SA01" \
9979
-i "pandas.Timedelta.max PR02" \

pandas/core/accessor.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import annotations
99

10+
import functools
1011
from typing import (
1112
TYPE_CHECKING,
1213
final,
@@ -117,12 +118,12 @@ def _setter(self, new_values):
117118
)
118119

119120
def _create_delegator_method(name: str):
121+
method = getattr(delegate, accessor_mapping(name))
122+
123+
@functools.wraps(method)
120124
def f(self, *args, **kwargs):
121125
return self._delegate_method(name, *args, **kwargs)
122126

123-
f.__name__ = name
124-
f.__doc__ = getattr(delegate, accessor_mapping(name)).__doc__
125-
126127
return f
127128

128129
for name in accessors:

pandas/core/arrays/categorical.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,12 @@ def rename_categories(self, new_categories) -> Self:
11551155
"""
11561156
Rename categories.
11571157
1158+
This method is commonly used to re-label or adjust the
1159+
category names in categorical data without changing the
1160+
underlying data. It is useful in situations where you want
1161+
to modify the labels used for clarity, consistency,
1162+
or readability.
1163+
11581164
Parameters
11591165
----------
11601166
new_categories : list-like, dict-like or callable
@@ -1371,8 +1377,8 @@ def remove_categories(self, removals) -> Self:
13711377
"""
13721378
Remove the specified categories.
13731379
1374-
`removals` must be included in the old categories. Values which were in
1375-
the removed categories will be set to NaN
1380+
The ``removals`` argument must be a subset of the current categories.
1381+
Any values that were part of the removed categories will be set to NaN.
13761382
13771383
Parameters
13781384
----------
@@ -1431,6 +1437,10 @@ def remove_unused_categories(self) -> Self:
14311437
"""
14321438
Remove categories which are not used.
14331439
1440+
This method is useful when working with datasets
1441+
that undergo dynamic changes where categories may no longer be
1442+
relevant, allowing to maintain a clean, efficient data structure.
1443+
14341444
Returns
14351445
-------
14361446
Categorical

0 commit comments

Comments
 (0)