Skip to content

Commit 501c4df

Browse files
authored
TST: catch warnings for to_hierarchical deprecation (#21744)
1 parent 9b24770 commit 501c4df

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pandas/tests/indexes/multi/test_conversion.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ def test_to_frame():
5757
def test_to_hierarchical():
5858
index = MultiIndex.from_tuples([(1, 'one'), (1, 'two'), (2, 'one'), (
5959
2, 'two')])
60-
result = index.to_hierarchical(3)
60+
with tm.assert_produces_warning(FutureWarning,
61+
check_stacklevel=False):
62+
result = index.to_hierarchical(3)
6163
expected = MultiIndex(levels=[[1, 2], ['one', 'two']],
6264
labels=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
6365
[0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]])
6466
tm.assert_index_equal(result, expected)
6567
assert result.names == index.names
6668

6769
# K > 1
68-
result = index.to_hierarchical(3, 2)
70+
with tm.assert_produces_warning(FutureWarning,
71+
check_stacklevel=False):
72+
result = index.to_hierarchical(3, 2)
6973
expected = MultiIndex(levels=[[1, 2], ['one', 'two']],
7074
labels=[[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
7175
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]])
@@ -77,7 +81,9 @@ def test_to_hierarchical():
7781
(2, 'a'), (2, 'b')],
7882
names=['N1', 'N2'])
7983

80-
result = index.to_hierarchical(2)
84+
with tm.assert_produces_warning(FutureWarning,
85+
check_stacklevel=False):
86+
result = index.to_hierarchical(2)
8187
expected = MultiIndex.from_tuples([(2, 'c'), (2, 'c'), (1, 'b'),
8288
(1, 'b'),
8389
(2, 'a'), (2, 'a'),

0 commit comments

Comments
 (0)