Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ Other Deprecations
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
- Deprecated positional arguments to :meth:`StringMethods.rsplit` except for ``pat``, use keyword-only arguments instead of positional arguments (:issue:`47423`)
- Deprecated indexing on a timezone-naive :class:`DatetimeIndex` using a string representing a timezone-aware datetime (:issue:`46903`, :issue:`36148`)
- Deprecated the ``closed`` argument in :class:`Interval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`IntervalIndex` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
DtypeObj,
F,
)
from pandas.util._decorators import Appender
from pandas.util._decorators import (
Appender,
deprecate_nonkeyword_arguments,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -874,6 +877,7 @@ def split(
"regex_examples": "",
}
)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
@forbid_nonstring_types(["bytes"])
def rsplit(self, pat=None, n=-1, expand=False):
result = self._data.array._str_rsplit(pat, n=n)
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/strings/test_split_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ def test_rsplit_max_number(any_string_dtype):
tm.assert_series_equal(result, exp)


def test_rsplit_posargs_deprecation():
# GH 47423; Deprecate passing n as positional.
s = Series(["foo,bar,lorep"])

msg = (
r"In a future version of pandas all arguments of StringMethods.rsplit "
r"except for the argument 'pat' will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
result = s.str.rsplit(",", 3)

expected = Series([["foo", "bar", "lorep"]])
tm.assert_series_equal(result, expected)


def test_split_blank_string(any_string_dtype):
# expand blank split GH 20067
values = Series([""], name="test", dtype=any_string_dtype)
Expand Down