Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Refactor _create_delegator_method using functools #59878

Merged
merged 26 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
eb5b998
add tag dt.to_timestamp, series.rst
saldanhad Sep 23, 2024
66f7453
add doc strings for dt.to_timestamp
saldanhad Sep 23, 2024
c5d9f54
update datetimes.py
saldanhad Sep 23, 2024
7efa1c6
refactor _create_delegator_method to use functools wrap
saldanhad Sep 24, 2024
7d61178
changes to accessor.py
saldanhad Sep 24, 2024
a81edf7
remove from code_checks.sh
saldanhad Sep 24, 2024
8b06215
update code_checks.sh
saldanhad Sep 24, 2024
bd4025a
update code_checks.sh
saldanhad Sep 24, 2024
a072c6b
rewrite functools, adjust unit tests
saldanhad Sep 24, 2024
f14e5cb
Merge branch 'main' into to_timestamp
saldanhad Oct 1, 2024
f027862
update change log
saldanhad Oct 1, 2024
22ebac1
Merge branch 'to_timestamp' of https://github.com/saldanhad/pandas-re…
saldanhad Oct 1, 2024
53bbc48
remove dup entry
saldanhad Oct 1, 2024
7498d59
update code_checks.sh
saldanhad Oct 1, 2024
23a58c2
update
saldanhad Oct 1, 2024
2e52720
Merge branch 'main' into to_timestamp
saldanhad Oct 5, 2024
c9f6094
revert all dt related changes
saldanhad Oct 5, 2024
c2d9c6e
Merge branch 'main' into to_timestamp
saldanhad Oct 5, 2024
4b03a0d
Merge branch 'to_timestamp' of https://github.com/saldanhad/pandas-re…
saldanhad Oct 5, 2024
ba44d87
update series.rst
saldanhad Oct 5, 2024
c7cc6db
update imports
saldanhad Oct 5, 2024
2e0f9a2
Merge branch 'main' into to_timestamp
saldanhad Oct 6, 2024
4115e04
format use of functools import
saldanhad Oct 6, 2024
1af3906
Merge branch 'to_timestamp' of https://github.com/saldanhad/pandas-re…
saldanhad Oct 6, 2024
8b93cad
Merge branch 'main' into to_timestamp
saldanhad Oct 7, 2024
10b4cab
Merge branch 'main' into to_timestamp
saldanhad Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 as ft
saldanhad marked this conversation as resolved.
Show resolved Hide resolved
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))

@ft.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
Loading