From a6b2c6d32666b0f3ecc4b6a3fd31ba8da38a588e Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 2 Dec 2018 13:07:33 +0100 Subject: [PATCH 1/3] TST/API: Forbid str-accessor for 1-level MultiIndex --- doc/source/whatsnew/v0.24.0.rst | 1 - doc/source/whatsnew/v0.25.0.rst | 2 ++ pandas/tests/test_strings.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 05d6a03639a2d..f64717a39aca9 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -434,7 +434,6 @@ Backwards incompatible API changes Pandas 0.24.0 includes a number of API breaking changes. - .. _whatsnew_0240.api_breaking.deps: Increased minimum versions for dependencies diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 87a8010998bd0..db1f970507b86 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -434,6 +434,8 @@ Other API Changes - The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`) - The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`) - Most Pandas classes had a ``__bytes__`` method, which was used for getting a python2-style bytestring representation of the object. This method has been removed as a part of dropping Python2 (:issue:`26447`) +- The `.str`-accessor has been disabled for 1-level :class:`MultiIndex` (almost all methods were previously broken for this case), + use :meth:`MultiIndex.to_flat_index` if necessary (:issue:`23679`) .. _whatsnew_0250.deprecations: diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 1ba0ef3918fb7..a1d522930e9aa 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -169,6 +169,14 @@ def test_api(self): assert Series.str is strings.StringMethods assert isinstance(Series(['']).str, strings.StringMethods) + def test_api_mi_raises(self): + # GH 23679 + mi = MultiIndex.from_arrays([['a', 'b', 'c']]) + with pytest.raises(AttributeError, match='Can only use .str accessor ' + 'with Index, not MultiIndex'): + mi.str + assert not hasattr(mi, 'str') + @pytest.mark.parametrize('dtype', [object, 'category']) @pytest.mark.parametrize('box', [Series, Index]) def test_api_per_dtype(self, box, dtype, any_skipna_inferred_dtype): From 763b79d214f5abb652c19b03da9c3f10b54fd40a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 1 Jun 2019 17:58:37 +0200 Subject: [PATCH 2/3] undo merge artefact --- doc/source/whatsnew/v0.24.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index f64717a39aca9..05d6a03639a2d 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -434,6 +434,7 @@ Backwards incompatible API changes Pandas 0.24.0 includes a number of API breaking changes. + .. _whatsnew_0240.api_breaking.deps: Increased minimum versions for dependencies From ebbec50d53504801268159def2cd873027e0ffaf Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 1 Jun 2019 21:23:15 +0200 Subject: [PATCH 3/3] Review (jreback) --- doc/source/whatsnew/v0.25.0.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index db1f970507b86..49ebb16b92292 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -434,8 +434,7 @@ Other API Changes - The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`) - The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`) - Most Pandas classes had a ``__bytes__`` method, which was used for getting a python2-style bytestring representation of the object. This method has been removed as a part of dropping Python2 (:issue:`26447`) -- The `.str`-accessor has been disabled for 1-level :class:`MultiIndex` (almost all methods were previously broken for this case), - use :meth:`MultiIndex.to_flat_index` if necessary (:issue:`23679`) +- The `.str`-accessor has been disabled for 1-level :class:`MultiIndex`, use :meth:`MultiIndex.to_flat_index` if necessary (:issue:`23679`) .. _whatsnew_0250.deprecations: