From 8cbf9eac7e3d20357e720ea9817a42e2fa72db3b Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 18 Nov 2018 16:28:39 +0100 Subject: [PATCH 1/2] API/DEPR: replace kwarg "pat" with "sep" in str.[r]partition --- doc/source/whatsnew/v0.24.0.rst | 1 + pandas/core/strings.py | 17 +++++++++++------ pandas/tests/test_strings.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 98941b6d353bb..0fd3a2f5177fe 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1030,6 +1030,7 @@ Deprecations - :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`) - The class ``FrozenNDArray`` has been deprecated. When unpickling, ``FrozenNDArray`` will be unpickled to ``np.ndarray`` once this class is removed (:issue:`9031`) - 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`) +- The methods :meth:`Series.str.partition` and :meth:`Series.str.rpartition` have deprecated the ``pat`` keyword in favor of ``sep`` (:issue:`22676`) - Deprecated the `nthreads` keyword of :func:`pandas.read_feather` in favor of `use_threads` to reflect the changes in pyarrow 0.11.0. (:issue:`23053`) - :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`) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 58ce562d03d1d..55efbc30738f4 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -19,7 +19,7 @@ from pandas.core.algorithms import take_1d import pandas.compat as compat from pandas.core.base import NoNewAttributesMixin -from pandas.util._decorators import Appender +from pandas.util._decorators import Appender, deprecate_kwarg import re import pandas._libs.lib as lib import pandas._libs.ops as libops @@ -2410,8 +2410,11 @@ def rsplit(self, pat=None, n=-1, expand=False): Parameters ---------- - pat : str, default whitespace + sep : str, default whitespace String to split on. + + .. versionchanged :: 0.24.0 + Changed name of parameter from `pat` to `sep`. expand : bool, default True If True, return DataFrame/MultiIndex expanding dimensionality. If False, return Series/Index. @@ -2485,8 +2488,9 @@ def rsplit(self, pat=None, n=-1, expand=False): 'empty strings', 'also': 'rpartition : Split the string at the last occurrence of `sep`' }) - def partition(self, pat=' ', expand=True): - f = lambda x: x.partition(pat) + @deprecate_kwarg(old_arg_name='pat', new_arg_name='sep') + def partition(self, sep=' ', expand=True): + f = lambda x: x.partition(sep) result = _na_map(f, self._parent) return self._wrap_result(result, expand=expand) @@ -2496,8 +2500,9 @@ def partition(self, pat=' ', expand=True): 'string itself', 'also': 'partition : Split the string at the first occurrence of `sep`' }) - def rpartition(self, pat=' ', expand=True): - f = lambda x: x.rpartition(pat) + @deprecate_kwarg(old_arg_name='pat', new_arg_name='sep') + def rpartition(self, sep=' ', expand=True): + f = lambda x: x.rpartition(sep) result = _na_map(f, self._parent) return self._wrap_result(result, expand=expand) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 7cd9182b4dff4..621f08e35bd4f 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -2586,6 +2586,24 @@ def test_partition_with_name(self): assert res.nlevels == 1 tm.assert_index_equal(res, exp) + def test_partition_deprecation(self): + # GH 22676; depr kwarg "pat" in favor of "sep" + values = Series(['a_b_c', 'c_d_e', NA, 'f_g_h']) + + # str.partition + # using sep -> no warning + expected = values.str.partition(sep='_') + with tm.assert_produces_warning(FutureWarning): + result = values.str.partition(pat='_') + tm.assert_frame_equal(result, expected) + + # str.rpartition + # using sep -> no warning + expected = values.str.rpartition(sep='_') + with tm.assert_produces_warning(FutureWarning): + result = values.str.rpartition(pat='_') + tm.assert_frame_equal(result, expected) + def test_pipe_failures(self): # #2119 s = Series(['A|B|C']) From 4e2d5e32b111c2e218646fd5cdfc7d3042c80882 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 18 Nov 2018 17:12:54 +0100 Subject: [PATCH 2/2] Review (WillAyd) --- pandas/core/strings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 55efbc30738f4..1c4317d56f82b 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2412,9 +2412,9 @@ def rsplit(self, pat=None, n=-1, expand=False): ---------- sep : str, default whitespace String to split on. - - .. versionchanged :: 0.24.0 - Changed name of parameter from `pat` to `sep`. + pat : str, default whitespace + .. deprecated:: 0.24.0 + Use ``sep`` instead expand : bool, default True If True, return DataFrame/MultiIndex expanding dimensionality. If False, return Series/Index.