Skip to content

TST/API: Forbid str-accessor for 1-level MultiIndex #26608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parenthetical is not necessary

did this actually work at some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods could be called but produced garbage, see #23679.

use :meth:`MultiIndex.to_flat_index` if necessary (:issue:`23679`)

.. _whatsnew_0250.deprecations:

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down