8000 DEPR: MultiIndex.to_hierarchical by KalyanGokhale · Pull Request #21613 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: MultiIndex.to_hierarchical #21613

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 8 commits into from
Jun 26, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Suppressed warnings
MItoHier
  • Loading branch information
KalyanGokhale committed Jun 25, 2018
commit 7aa3bbfef5439ad6e15c91da12e649d407a65b60
17 changes: 8 additions & 9 deletions pandas/tests/indexes/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,15 +1675,19 @@ def test_to_frame(self):
def test_to_hierarchical(self):
index = MultiIndex.from_tuples([(1, 'one'), (1, 'two'), (2, 'one'), (
2, 'two')])
result = index.to_hierarchical(3)
# GH21613
# Suppressed deprecation warnings in this original test
Copy link
Contributor

Choose a reason for hiding this comment

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

these comments are not needed, move the gh issue number to the top of this method

with tm.assert_produces_warning(FutureWarning):
result = index.to_hierarchical(3)
expected = MultiIndex(levels=[[1, 2], ['one', 'two']],
labels=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]])
tm.assert_index_equal(result, expected)
assert result.names == index.names

# K > 1
result = index.to_hierarchical(3, 2)
with tm.assert_produces_warning(FutureWarning):
result = index.to_hierarchical(3, 2)
expected = MultiIndex(levels=[[1, 2], ['one', 'two']],
labels=[[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]])
Expand All @@ -1694,8 +1698,8 @@ def test_t 8000 o_hierarchical(self):
index = MultiIndex.from_tuples([(2, 'c'), (1, 'b'),
(2, 'a'), (2, 'b')],
names=['N1', 'N2'])

result = index.to_hierarchical(2)
with tm.assert_produces_warning(FutureWarning):
result = index.to_hierarchical(2)
expected = MultiIndex.from_tuples([(2, 'c'), (2, 'c'), (1, 'b'),
(1, 'b'),
(2, 'a'), (2, 'a'),
Expand All @@ -1704,11 +1708,6 @@ def test_to_hierarchical(self):
tm.assert_index_equal(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to catch all uses of to_hierarchical (or you get the warnings)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - not sure if I understand.
The only use of to_hierarchical was in pandas/core/panel.py- this has been substituted.
This existing test is specifically for to_hierarchical - which can be removed once this method is removed in a future version - should these tests be removed as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback I think after reviewing changes in #18258 I probably get what is expected - please ignore the comment above - will update

assert result.names == index.names

# GH21613
# .to_hierarchical will be deprecated
with tm.assert_produces_warning(FutureWarning):
result = index.to_hierarchical(2)

def test_bounds(self):
self.index._bounds

Expand Down
0