Skip to content

Commit 7efa1c6

Browse files
committed
refactor _create_delegator_method to use functools wrap
1 parent c5d9f54 commit 7efa1c6

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

pandas/core/accessor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ def _setter(self, new_values):
116116
doc=getattr(delegate, accessor_mapping(name)).__doc__,
117117
)
118118

119+
from functools import wraps
120+
119121
def _create_delegator_method(name: str):
120-
def f(self, *args, **kwargs):
121-
return self._delegate_method(name, *args, **kwargs)
122+
original_method = getattr(delegate, accessor_mapping(name))
122123

123-
f.__name__ = name
124-
f.__doc__ = getattr(delegate, accessor_mapping(name)).__doc__
124+
@wraps(original_method)
125+
def f(self):
126+
return self._delegate_method(name)
125127

126128
return f
127129

pandas/core/arrays/categorical.py

Lines changed: 12 additions & 2 deletions
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+
``removals`` must be included in the old categories,
1381+
values which were in 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)