{"record":{"id":"d8af9961b9723792","repo":"pandas-dev/pandas","slug":"array-with-ndim-2-is-not-supported","errorCode":null,"errorMessage":"Array with ndim > 2 is not supported.","messagePattern":"Array with ndim > 2 is not supported\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/algorithms.py","lineNumber":1254,"sourceCode":"            ties_method=method,\n            ascending=ascending,\n            na_option=na_option,\n            pct=pct,\n            mask=mask,\n        )\n    elif values.ndim == 2:\n        assert mask is None\n        ranks = algos.rank_2d(\n            values,\n            axis=axis,\n            is_datetimelike=is_datetimelike,\n            ties_method=method,\n            ascending=ascending,\n            na_option=na_option,\n            pct=pct,\n        )\n    else:\n        raise TypeError(\"Array with ndim > 2 is not supported.\")\n\n    return ranks\n\n\ndef is_monotonic(values: ArrayLike) -> tuple[bool, bool, bool]:\n    \"\"\"\n    Determine whether values are monotonic increasing/decreasing.\n\n    Parameters\n    ----------\n    values : np.ndarray or ExtensionArray\n\n    Returns\n    -------\n    tuple[bool, bool, bool]\n        (is_monotonic_increasing, is_monotonic_decreasing, is_strict_monotonic)\n\n    Raises","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/algorithms.py#L1236-L1272","documentation":"Raised by pandas.core.algorithms.rank when the input array has more than 2 dimensions. rank only implements 1-D (rank_1d) and 2-D (rank_2d) paths; a 3-D+ array (e.g. a stacked tensor) has no supported ranking axis mapping.","triggerScenarios":"Calling rank on a 3-D numpy array, or constructing a DataFrame/array whose underlying values are 3-D and routing it through the rank algorithm; reshaping data into ndim>2 before ranking.","commonSituations":"Multi-indexed/panel-like data flattened into a 3-D ndarray; passing raw np.ndarray of shape (n, m, k) to rank; custom ExtensionArray whose _values is 3-D.","solutions":["Reduce to 1-D or 2-D before ranking (reshape, stack, or loop over the extra dimension).","Rank a 2-D slice (arr[:, :, 0]) and iterate over the third axis.","Use DataFrame.rank on a proper 2-D frame instead of a 3-D array."],"exampleFix":"# before\narr = np.arange(24).reshape(2, 3, 4)\npd.core.algorithms.rank(arr)\n# after\nranks = np.empty_like(arr, dtype=float)\nfor k in range(arr.shape[2]):\n    ranks[:, :, k] = pd.core.algorithms.rank(arr[:, :, k])","handlingStrategy":"validation","validationCode":"import numpy as np, pandas as pd\n\ndef rank_any(arr, **kw):\n    arr = np.asarray(arr)\n    if arr.ndim > 2:\n        out = np.empty(arr.shape, dtype=float)\n        for idx in np.ndindex(arr.shape[2:]):\n            full = (slice(None), slice(None)) + idx\n            out[full] = pd.core.algorithms.rank(arr[full], **kw)\n        return out\n    return pd.core.algorithms.rank(arr, **kw)","typeGuard":"import numpy as np\n\ndef is_rankable(arr) -> bool:\n    return np.asarray(arr).ndim <= 2","tryCatchPattern":null,"preventionTips":["Reduce ndim to <=2 before calling rank.","Rank 2-D slices and iterate the extra axes.","Use DataFrame.rank on proper 2-D frames."],"tags":["rank","ndim","ndarray","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}