Skip to content

Commit dd95741

Browse files
preserve signature deprecate_kwarg follow-on #28128
1 parent 523f9c8 commit dd95741

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def astype(self, dtype, copy=True):
736736
return Index(new_values, dtype=new_values.dtype, name=self.name, copy=False)
737737

738738
@deprecate_kwarg(old_arg_name="n", new_arg_name="periods")
739-
def shift(self, periods, freq=None):
739+
def shift(self, periods=1, freq=None):
740740
"""
741741
Shift index by desired number of time frequency increments.
742742

pandas/util/_decorators.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# error: No library stub file for module 'pandas._libs.properties'
1919
from pandas._libs.properties import cache_readonly # type: ignore # noqa
2020

21-
FuncType = Callable[..., Any]
22-
F = TypeVar("F", bound=FuncType)
21+
_FuncType = Callable[..., Any]
22+
_F = TypeVar("_F", bound=_FuncType)
2323

2424

2525
def deprecate(
@@ -107,7 +107,7 @@ def deprecate_kwarg(
107107
new_arg_name: Optional[str],
108108
mapping: Optional[Union[Dict[Any, Any], Callable[[Any], Any]]] = None,
109109
stacklevel: int = 2,
110-
) -> Callable[..., Any]:
110+
) -> Callable[[_F], _F]:
111111
"""
112112
Decorator to deprecate a keyword argument of a function.
113113
@@ -175,7 +175,7 @@ def deprecate_kwarg(
175175
"mapping from old to new argument values " "must be dict or callable!"
176176
)
177177

178-
def _deprecate_kwarg(func: F) -> F:
178+
def _deprecate_kwarg(func: _F) -> _F:
179179
@wraps(func)
180180
def wrapper(*args, **kwargs) -> Callable[..., Any]:
181181
old_arg_value = kwargs.pop(old_arg_name, None)
@@ -222,15 +222,15 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
222222
kwargs[new_arg_name] = new_arg_value
223223
return func(*args, **kwargs)
224224

225-
return cast(F, wrapper)
225+
return cast(_F, wrapper)
226226

227227
return _deprecate_kwarg
228228

229229

230230
def rewrite_axis_style_signature(
231231
name: str, extra_params: List[Tuple[str, Any]]
232232
) -> Callable[..., Any]:
233-
def decorate(func: F) -> F:
233+
def decorate(func: _F) -> _F:
234234
@wraps(func)
235235
def wrapper(*args, **kwargs) -> Callable[..., Any]:
236236
return func(*args, **kwargs)
@@ -251,7 +251,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
251251

252252
# https://github.com/python/typing/issues/598
253253
func.__signature__ = sig # type: ignore
254-
return cast(F, wrapper)
254+
return cast(_F, wrapper)
255255

256256
return decorate
257257

@@ -295,7 +295,7 @@ def __init__(self, *args, **kwargs):
295295

296296
self.params = args or kwargs
297297

298-
def __call__(self, func: F) -> F:
298+
def __call__(self, func: _F) -> _F:
299299
func.__doc__ = func.__doc__ and func.__doc__ % self.params
300300
return func
301301

@@ -335,7 +335,7 @@ def __init__(self, addendum: Optional[str], join: str = "", indents: int = 0):
335335
self.addendum = addendum
336336
self.join = join
337337

338-
def __call__(self, func: F) -> F:
338+
def __call__(self, func: _F) -> _F:
339339
func.__doc__ = func.__doc__ if func.__doc__ else ""
340340
self.addendum = self.addendum if self.addendum else ""
341341
docitems = [func.__doc__, self.addendum]

0 commit comments

Comments
 (0)