pandas-dev/pandas · error · ValueError
multi-dimensional indexing not allowed
Error message
multi-dimensional indexing not allowed
What it means
Raised in `IntervalArray.__getitem__` when the indexer yields a left/right with `np.ndim(left) > 1`. IntervalArray is 1-D; a 2-D indexer (e.g. a 2-D boolean mask, or `arr[arr_idx, col_idx]` style) is not supported (GH#30588).
Solutions
- Flatten the indexer: use `.ravel()` on the mask or pick a single row/column first.
- Index with a 1-D boolean array or integer positions only.
- If you need 2-D selection, work on a DataFrame whose column is the interval, not on the bare IntervalArray.
Example fix
# before mask = np.array([[True, False], [False, True]]) arr[mask] # after arr[mask.ravel()] # 1-D indexer
Defensive patterns
Strategy: validation
Validate before calling
import numpy as np
def to_1d_indexer(key):
arr = np.asarray(key)
if arr.ndim > 1:
raise ValueError('indexer must be 1-D')
return key Type guard
import numpy as np
def is_1d_indexer(key) -> bool:
arr = np.asarray(key)
return arr.ndim <= 1 Try / catch
try:
sub = arr[key]
except ValueError as e:
if 'multi-dimensional indexing not allowed' in str(e):
sub = arr[np.asarray(key).ravel()]
else:
raise Prevention
- Flatten 2-D masks with .ravel() before indexing an IntervalArray.
- Do not chain [row, col] indexers on a 1-D array.
- Perform 2-D selection on a DataFrame, not on the bare array.
When it happens
Trigger: `arr[two_dim_mask]` where the mask is shape (n, m); `arr[np.array([[0,1]])]`; passing a DataFrame as a boolean indexer.
Common situations: User mistakenly applying a 2-D mask meant for a DataFrame; chaining indexers `[row_idx, col_idx]` on a 1-D array; reshaping bugs producing 2-D index arrays.
Related errors
- Cannot mask with non-boolean array containing NA / NaN…
- Cannot modify read-only array
- closed keyword does not match dtype.closed
- invalid dtype
- left and right must have the same length
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/ae7e300df275526b.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/interval.py:684
@overload
def __getitem__(self, key: ScalarIndexer) -> IntervalOrNA: ...
@overload
def __getitem__(self, key: SequenceIndexer) -> Self: ...
def __getitem__(self, key: PositionalIndexer) -> Self | IntervalOrNA:
key = check_array_indexer(self, key)
left = self._left[key]
right = self._right[key]
if not isinstance(left, (np.ndarray, ExtensionArray)):
# scalar
if is_scalar(left) and isna(left):
return self._fill_value
return Interval(left, right, self.closed)
if np.ndim(left) > 1:
# GH#30588 multi-dimensional indexer disallowed
raise ValueError("multi-dimensional indexing not allowed")
# Argument 2 to "_simple_new" of "IntervalArray" has incompatible type
# "Union[Period, Timestamp, Timedelta, NaTType, DatetimeArray, TimedeltaArray,
# ndarray[Any, Any]]"; expected "Union[Union[DatetimeArray, TimedeltaArray],
# ndarray[Any, Any]]"
result = self._simple_new(left, right, dtype=self.dtype) # type: ignore[arg-type]
if getitem_returns_view(self, key):
result._readonly = self._readonly
return result
def __setitem__(self, key, value) -> None:
if self._readonly:
raise ValueError("Cannot modify read-only array")
key = check_array_indexer(self, key)
value_left, value_right = self._validate_setitem_value(value)
self._left[key] = value_left
self._right[key] = value_rightView on GitHub (pinned to 3b7651241d)