Skip to content

Commit b2fe1c8

Browse files
h-vetinarijreback
authored andcommitted
API/DEPR: replace kwarg "pat" with "sep" in str.[r]partition (#23767)
1 parent 6fad5a0 commit b2fe1c8

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ Deprecations
10351035
- :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` have deprecated the ``errors`` argument in favor of the ``nonexistent`` argument (:issue:`8917`)
10361036
- The class ``FrozenNDArray`` has been deprecated. When unpickling, ``FrozenNDArray`` will be unpickled to ``np.ndarray`` once this class is removed (:issue:`9031`)
10371037
- The methods :meth:`DataFrame.update` and :meth:`Panel.update` have deprecated the ``raise_conflict=False|True`` keyword in favor of ``errors='ignore'|'raise'`` (:issue:`23585`)
1038+
- The methods :meth:`Series.str.partition` and :meth:`Series.str.rpartition` have deprecated the ``pat`` keyword in favor of ``sep`` (:issue:`22676`)
10381039
- Deprecated the `nthreads` keyword of :func:`pandas.read_feather` in favor of
10391040
`use_threads` to reflect the changes in pyarrow 0.11.0. (:issue:`23053`)
10401041
- :func:`pandas.read_excel` has deprecated accepting ``usecols`` as an integer. Please pass in a list of ints from 0 to ``usecols`` inclusive instead (:issue:`23527`)

pandas/core/strings.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from pandas.core.algorithms import take_1d
2020
import pandas.compat as compat
2121
from pandas.core.base import NoNewAttributesMixin
22-
from pandas.util._decorators import Appender
22+
from pandas.util._decorators import Appender, deprecate_kwarg
2323
import re
2424
import pandas._libs.lib as lib
2525
import pandas._libs.ops as libops
@@ -2410,8 +2410,11 @@ def rsplit(self, pat=None, n=-1, expand=False):
24102410
24112411
Parameters
24122412
----------
2413-
pat : str, default whitespace
2413+
sep : str, default whitespace
24142414
String to split on.
2415+
pat : str, default whitespace
2416+
.. deprecated:: 0.24.0
2417+
Use ``sep`` instead
24152418
expand : bool, default True
24162419
If True, return DataFrame/MultiIndex expanding dimensionality.
24172420
If False, return Series/Index.
@@ -2485,8 +2488,9 @@ def rsplit(self, pat=None, n=-1, expand=False):
24852488
'empty strings',
24862489
'also': 'rpartition : Split the string at the last occurrence of `sep`'
24872490
})
2488-
def partition(self, pat=' ', expand=True):
2489-
f = lambda x: x.partition(pat)
2491+
@deprecate_kwarg(old_arg_name='pat', new_arg_name='sep')
2492+
def partition(self, sep=' ', expand=True):
2493+
f = lambda x: x.partition(sep)
24902494
result = _na_map(f, self._parent)
24912495
return self._wrap_result(result, expand=expand)
24922496

@@ -2496,8 +2500,9 @@ def partition(self, pat=' ', expand=True):
24962500
'string itself',
24972501
'also': 'partition : Split the string at the first occurrence of `sep`'
24982502
})
2499-
def rpartition(self, pat=' ', expand=True):
2500-
f = lambda x: x.rpartition(pat)
2503+
@deprecate_kwarg(old_arg_name='pat', new_arg_name='sep')
2504+
def rpartition(self, sep=' ', expand=True):
2505+
f = lambda x: x.rpartition(sep)
25012506
result = _na_map(f, self._parent)
25022507
return self._wrap_result(result, expand=expand)
25032508

pandas/tests/test_strings.py

+18
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,24 @@ def test_partition_with_name(self):
26092609
assert res.nlevels == 1
26102610
tm.assert_index_equal(res, exp)
26112611

2612+
def test_partition_deprecation(self):
2613+
# GH 22676; depr kwarg "pat" in favor of "sep"
2614+
values = Series(['a_b_c', 'c_d_e', NA, 'f_g_h'])
2615+
2616+
# str.partition
2617+
# using sep -> no warning
2618+
expected = values.str.partition(sep='_')
2619+
with tm.assert_produces_warning(FutureWarning):
2620+
result = values.str.partition(pat='_')
2621+
tm.assert_frame_equal(result, expected)
2622+
2623+
# str.rpartition
2624+
# using sep -> no warning
2625+
expected = values.str.rpartition(sep='_')
2626+
with tm.assert_produces_warning(FutureWarning):
2627+
result = values.str.rpartition(pat='_')
2628+
tm.assert_frame_equal(result, expected)
2629+
26122630
def test_pipe_failures(self):
26132631
# #2119
26142632
s = Series(['A|B|C'])

0 commit comments

Comments
 (0)