Skip to content

Commit

Permalink
DOC: Refactor _create_delegator_method using functools (#59878)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
saldanhad authored Oct 8, 2024
1 parent 5ea5bd9 commit f94860e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
20 changes: 0 additions & 20 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Period.freq GL08" \
-i "pandas.Period.ordinal GL08" \
-i "pandas.RangeIndex.from_range PR01,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" \
-i "pandas.Series.cat.remove_unused_categories PR01" \
-i "pandas.Series.cat.rename_categories PR01,PR02" \
-i "pandas.Series.cat.reorder_categories PR01,PR02" \
-i "pandas.Series.cat.set_categories PR01,PR02" \
-i "pandas.Series.dt.as_unit PR01,PR02" \
-i "pandas.Series.dt.ceil PR01,PR02" \
-i "pandas.Series.dt.day_name PR01,PR02" \
-i "pandas.Series.dt.floor PR01,PR02" \
-i "pandas.Series.dt.freq GL08" \
-i "pandas.Series.dt.month_name PR01,PR02" \
-i "pandas.Series.dt.normalize PR01" \
-i "pandas.Series.dt.round PR01,PR02" \
-i "pandas.Series.dt.strftime PR01,PR02" \
-i "pandas.Series.dt.to_period PR01,PR02" \
-i "pandas.Series.dt.total_seconds PR01" \
-i "pandas.Series.dt.tz_convert PR01,PR02" \
-i "pandas.Series.dt.tz_localize PR01,PR02" \
-i "pandas.Series.dt.unit GL08" \
-i "pandas.Series.pad PR01,SA01" \
-i "pandas.Timedelta.max PR02" \
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

import functools
from typing import (
TYPE_CHECKING,
final,
Expand Down Expand Up @@ -117,12 +118,12 @@ def _setter(self, new_values):
)

def _create_delegator_method(name: str):
method = getattr(delegate, accessor_mapping(name))

@functools.wraps(method)
def f(self, *args, **kwargs):
return self._delegate_method(name, *args, **kwargs)

f.__name__ = name
f.__doc__ = getattr(delegate, accessor_mapping(name)).__doc__

return f

for name in accessors:
Expand Down
14 changes: 12 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,12 @@ def rename_categories(self, new_categories) -> Self:
"""
Rename categories.
This method is commonly used to re-label or adjust the
category names in categorical data without changing the
underlying data. It is useful in situations where you want
to modify the labels used for clarity, consistency,
or readability.
Parameters
----------
new_categories : list-like, dict-like or callable
Expand Down Expand Up @@ -1371,8 +1377,8 @@ def remove_categories(self, removals) -> Self:
"""
Remove the specified categories.
`removals` must be included in the old categories. Values which were in
the removed categories will be set to NaN
The ``removals`` argument must be a subset of the current categories.
Any values that were part of the removed categories will be set to NaN.
Parameters
----------
Expand Down Expand Up @@ -1431,6 +1437,10 @@ def remove_unused_categories(self) -> Self:
"""
Remove categories which are not used.
This method is useful when working with datasets
that undergo dynamic changes where categories may no longer be
relevant, allowing to maintain a clean, efficient data structure.
Returns
-------
Categorical
Expand Down

0 comments on commit f94860e

Please sign in to comment.