{"record":{"id":"6327581ce48d01cb","repo":"pandas-dev/pandas","slug":"cannot-slice-with-ellipsis","errorCode":null,"errorMessage":"Cannot slice with Ellipsis","messagePattern":"Cannot slice with Ellipsis","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/sparse/array.py","lineNumber":1049,"sourceCode":"            index = Index(keys, copy=False)\n        else:\n            index = keys\n        return Series(counts, index=index, copy=False)\n\n    # --------\n    # Indexing\n    # --------\n    @overload\n    def __getitem__(self, key: ScalarIndexer) -> Any: ...\n\n    @overload\n    def __getitem__(self, key: SequenceIndexer) -> Self: ...\n\n    def __getitem__(self, key: PositionalIndexer) -> Self | Any:\n        if isinstance(key, tuple):\n            key = unpack_tuple_and_ellipses(key)\n            if key is ...:\n                raise ValueError(\"Cannot slice with Ellipsis\")\n\n        if is_integer(key):\n            return self._get_val_at(key)\n        elif isinstance(key, tuple):\n            data_slice = self.to_dense()[key]\n        elif isinstance(key, slice):\n            if key == slice(None):\n                # to ensure arr[:] (used by view()) does not make a copy\n                result = type(self)._simple_new(\n                    self.sp_values, self.sp_index, self.dtype\n                )\n                result._readonly = self._readonly\n                return result\n            # Avoid densifying when handling contiguous slices\n            if key.step is None or key.step == 1:\n                start = 0 if key.start is None else key.start\n                if start < 0:\n                    start += len(self)","sourceCodeStart":1031,"sourceCodeEnd":1067,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/sparse/array.py#L1031-L1067","documentation":"Raised by SparseArray.__getitem__ when a tuple key unpacks to Ellipsis. SparseArray's __getitem__ supports integer, slice, and list-like keys but does not implement ndarray-style Ellipsis expansion, so a leftover Ellipsis is treated as an invalid slice.","triggerScenarios":"Indexing arr[..., 0], arr[Ellipsis], or passing a tuple containing Ellipsis that unpack_tuple_and_ellipses cannot fully eliminate for a 1-D sparse array.","commonSituations":"Generic N-D indexing code reused against a 1-D SparseArray; numpy-style ellipsis indexing ported from dense arrays.","solutions":["Remove the Ellipsis; index directly as arr[0] or arr[:].","Normalize keys before indexing: drop Ellipsis for 1-D sparse arrays.","Materialize to dense with np.asarray(arr)[key] if Ellipsis semantics are required."],"exampleFix":"// before\narr[..., 0]  # raises\n// after\narr[0]","handlingStrategy":"validation","validationCode":"def strip_ellipsis_key(key):\n    import numpy as np\n    if isinstance(key, tuple):\n        key = tuple(k for k in key if k is not ...)\n        return key[0] if len(key) == 1 else key\n    return key","typeGuard":"def key_has_ellipsis(key) -> bool:\n    return key is ... or (isinstance(key, tuple) and ... in key)","tryCatchPattern":"try:\n    arr[key]\nexcept ValueError as e:\n    if \"Cannot slice with Ellipsis\" in str(e):\n        key = strip_ellipsis_key(key)\n        out = arr[key]\n    else:\n        raise","preventionTips":["Avoid Ellipsis in 1-D sparse indexing.","Normalize tuple keys before indexing SparseArray."],"tags":["sparse","indexing","ellipsis","getitem"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}