Skip to content

Commit b1e4c55

Browse files
h-vetinarivaibhavhrt
authored andcommitted
TST/API: Forbid str-accessor for 1-level MultiIndex (pandas-dev#26608)
1 parent 21f49c4 commit b1e4c55

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ Other API Changes
434434
- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`)
435435
- The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`)
436436
- 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`)
437+
- The `.str`-accessor has been disabled for 1-level :class:`MultiIndex`, use :meth:`MultiIndex.to_flat_index` if necessary (:issue:`23679`)
437438
- Removed support of gtk package for clipboards (:issue:`26563`)
438439

439440
.. _whatsnew_0250.deprecations:

pandas/tests/test_strings.py

+8
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ def test_api(self):
169169
assert Series.str is strings.StringMethods
170170
assert isinstance(Series(['']).str, strings.StringMethods)
171171

172+
def test_api_mi_raises(self):
173+
# GH 23679
174+
mi = MultiIndex.from_arrays([['a', 'b', 'c']])
175+
with pytest.raises(AttributeError, match='Can only use .str accessor '
176+
'with Index, not MultiIndex'):
177+
mi.str
178+
assert not hasattr(mi, 'str')
179+
172180
@pytest.mark.parametrize('dtype', [object, 'category'])
173181
@pytest.mark.parametrize('box', [Series, Index])
174182
def test_api_per_dtype(self, box, dtype, any_skipna_inferred_dtype):

0 commit comments

Comments
 (0)