Skip to content

Commit 616c357

Browse files
author
eric
committed
Add examples of how to deprecate a keyword, and fix spacing.
1 parent ab47916 commit 616c357

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pandas/tests/test_algos.py

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def test_uint64_factorize(self):
249249
tm.assert_numpy_array_equal(uniques, exp_uniques)
250250

251251
def test_deprecate_order(self):
252+
# gh 19727 - check warning is raised for deprecated keyword, order.
253+
# Test not valid once order keyword is removed.
252254
data = np.array([2**63, 1, 2**63], dtype=np.uint64)
253255
with tm.assert_produces_warning(expected_warning=FutureWarning):
254256
algos.factorize(data, order=True)

pandas/util/_decorators.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ def deprecate_kwarg(old_arg_name, new_arg_name, mapping=None, stacklevel=2):
9797
FutureWarning: old='yes' is deprecated, use new=True instead
9898
warnings.warn(msg, FutureWarning)
9999
yes!
100+
101+
102+
To raise a warning that a keyword will be removed entirely in the future
103+
104+
>>> @deprecate_kwarg(old_arg_name='cols', new_arg_name=None)
105+
... def f(cols='', another_param=''):
106+
... print(cols)
107+
...
108+
>>> f(cols='should raise warning')
109+
FutureWarning: the 'cols' keyword is deprecated and will be removed in a
110+
future version please takes steps to stop use of 'cols'
111+
should raise warning
112+
>>> f(another_param='should not raise warning')
113+
should not raise warning
114+
>>> f(cols='should raise warning', another_param='')
115+
FutureWarning: the 'cols' keyword is deprecated and will be removed in a
116+
future version please takes steps to stop use of 'cols'
117+
should raise warning
100118
"""
101119

102120
if mapping is not None and not hasattr(mapping, 'get') and \
@@ -111,8 +129,8 @@ def wrapper(*args, **kwargs):
111129

112130
if new_arg_name is None and old_arg_value is not None:
113131
msg = (
114-
"the '{old_name}' keyword is deprecated and will be"
115-
"removed in a future version"
132+
"the '{old_name}' keyword is deprecated and will be "
133+
"removed in a future version "
116134
"please takes steps to stop use of '{old_name}'"
117135
).format(old_name=old_arg_name)
118136
warnings.warn(msg, FutureWarning, stacklevel=stacklevel)

0 commit comments

Comments
 (0)