Skip to content

Commit 3d9027b

Browse files
MrShevanAnton Shevtsov
authored andcommitted
Deprecate non-keyword arguments for rsplit (pandas-dev#47446)
* Deprecate non-keyword arguments for rsplit * linter fix * Deprecate non-keyword arguments for split Co-authored-by: Anton Shevtsov <[email protected]>
1 parent 673b7b9 commit 3d9027b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ Other Deprecations
705705
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
706706
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
707707
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
708+
- Deprecated positional arguments to :meth:`StringMethods.rsplit` and :meth:`StringMethods.split` except for ``pat``, use keyword-only arguments instead of positional arguments (:issue:`47423`)
708709
- Deprecated indexing on a timezone-naive :class:`DatetimeIndex` using a string representing a timezone-aware datetime (:issue:`46903`, :issue:`36148`)
709710
- Deprecated the ``closed`` argument in :class:`Interval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
710711
- Deprecated the ``closed`` argument in :class:`IntervalIndex` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)

pandas/core/strings/accessor.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
DtypeObj,
1919
F,
2020
)
21-
from pandas.util._decorators import Appender
21+
from pandas.util._decorators import (
22+
Appender,
23+
deprecate_nonkeyword_arguments,
24+
)
2225
from pandas.util._exceptions import find_stack_level
2326

2427
from pandas.core.dtypes.common import (
@@ -843,6 +846,7 @@ def cat(
843846
""",
844847
}
845848
)
849+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
846850
@forbid_nonstring_types(["bytes"])
847851
def split(
848852
self,
@@ -874,6 +878,7 @@ def split(
874878
"regex_examples": "",
875879
}
876880
)
881+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
877882
@forbid_nonstring_types(["bytes"])
878883
def rsplit(self, pat=None, n=-1, expand=False):
879884
result = self._data.array._str_rsplit(pat, n=n)

pandas/tests/strings/test_split_partition.py

+17
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ def test_rsplit_max_number(any_string_dtype):
130130
tm.assert_series_equal(result, exp)
131131

132132

133+
@pytest.mark.parametrize("method", ["split", "rsplit"])
134+
def test_posargs_deprecation(method):
135+
# GH 47423; Deprecate passing n as positional.
136+
s = Series(["foo,bar,lorep"])
137+
138+
msg = (
139+
f"In a future version of pandas all arguments of StringMethods.{method} "
140+
"except for the argument 'pat' will be keyword-only"
141+
)
142+
143+
with tm.assert_produces_warning(FutureWarning, match=msg):
144+
result = getattr(s.str, method)(",", 3)
145+
146+
expected = Series([["foo", "bar", "lorep"]])
147+
tm.assert_series_equal(result, expected)
148+
149+
133150
def test_split_blank_string(any_string_dtype):
134151
# expand blank split GH 20067
135152
values = Series([""], name="test", dtype=any_string_dtype)

0 commit comments

Comments
 (0)