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

Deprecate non-keyword arguments for rsplit #47446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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` and :meth:`StringMethods.split` 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
7 changes: 6 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 @@ -843,6 +846,7 @@ def cat(
""",
}
)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
@forbid_nonstring_types(["bytes"])
def split(
self,
Expand Down Expand Up @@ -874,6 +878,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
17 changes: 17 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,23 @@ def test_rsplit_max_number(any_string_dtype):
tm.assert_series_equal(result, exp)


@pytest.mark.parametrize("method", ["split", "rsplit"])
def test_posargs_deprecation(method):
# GH 47423; Deprecate passing n as positional.
s = Series(["foo,bar,lorep"])

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

with tm.assert_produces_warning(FutureWarning, match=msg):
result = getattr(s.str, method)(",", 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