Skip to content

Commit bf5703a

Browse files
authored
BUG: stacklevel for multidimensional indexing warning #31479 (#41969)
1 parent 8d143fd commit bf5703a

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

pandas/core/indexers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AnyArrayLike,
1414
ArrayLike,
1515
)
16+
from pandas.util._exceptions import find_stack_level
1617

1718
from pandas.core.dtypes.common import (
1819
is_array_like,
@@ -375,7 +376,7 @@ def deprecate_ndim_indexing(result, stacklevel: int = 3):
375376
"is deprecated and will be removed in a future "
376377
"version. Convert to a numpy array before indexing instead.",
377378
FutureWarning,
378-
stacklevel=stacklevel,
379+
stacklevel=find_stack_level(),
379380
)
380381

381382

pandas/tests/indexes/common.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,10 @@ def test_engine_reference_cycle(self, simple_index):
724724
assert len(gc.get_referrers(index)) == nrefs_pre
725725

726726
def test_getitem_2d_deprecated(self, simple_index):
727-
# GH#30588
727+
# GH#30588, GH#31479
728728
idx = simple_index
729729
msg = "Support for multi-dimensional indexing"
730-
check = not isinstance(idx, (RangeIndex, CategoricalIndex))
731-
with tm.assert_produces_warning(
732-
FutureWarning, match=msg, check_stacklevel=check
733-
):
730+
with tm.assert_produces_warning(FutureWarning, match=msg):
734731
res = idx[:, None]
735732

736733
assert isinstance(res, np.ndarray), type(res)

0 commit comments

Comments
 (0)