Skip to content

Commit

Permalink
Deprecate non-keyword arguments for rsplit (pandas-dev#47446)
Browse files Browse the repository at this point in the history
* Deprecate non-keyword arguments for rsplit

* linter fix

* Deprecate non-keyword arguments for split

Co-authored-by: Anton Shevtsov <aeshevtsov@avito.ru>
  • Loading branch information
2 people authored and yehoshuadimarsky committed Jul 13, 2022
1 parent 673b7b9 commit 3d9027b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit 3d9027b

Please sign in to comment.