{"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":1044,"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":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/sparse/array.py#L1026-L1062","documentation":"Raised in SparseArray.__getitem__ when the key is a tuple that, after unpack_tuple_and_ellipses, reduces to a bare Ellipsis. SparseArray's optimized __getitem__ does not implement the Ellipsis-as-full-slice path for tuple keys, so it rejects it explicitly rather than falling through.","triggerScenarios":"sparse_arr[(Ellipsis,)]; sparse_arr[..., ...] collapsing to ...; code that programmatically builds tuple keys including Ellipsis for n-D compatibility.","commonSituations":"Generic n-D indexing helpers that always insert Ellipsis; forwarding matrix-style keys to a 1-D array; copy-paste from DataFrame indexing.","solutions":["Use a full slice instead: sparse_arr[:] returns the whole array via the slice(None) fast path.","Strip Ellipsis from programmatic keys before indexing: key = slice(None) if key is ... else key.","Avoid tuple keys for 1-D SparseArray; pass a scalar, slice, or array directly."],"exampleFix":"// before\nsparse_arr[(Ellipsis,)]\n// after\nsparse_arr[:]","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef getitem_sparse(arr, key):\n    if isinstance(key, tuple):\n        from pandas.core.indexers import unpack_tuple_and_ellipses\n        key = unpack_tuple_and_ellipses(key)\n    if key is ...:\n        key = slice(None)\n    return arr[key]","typeGuard":"def is_safe_sparse_key(key) -> bool:\n    return key is not Ellipsis and not (isinstance(key, tuple) and Ellipsis in key)","tryCatchPattern":"try:\n    return arr[key]\nexcept ValueError as e:\n    if 'Ellipsis' in str(e):\n        return arr[slice(None)]\n    raise","preventionTips":["Use arr[:] instead of Ellipsis for full-array access.","Strip Ellipsis from programmatic tuple keys before indexing.","Avoid tuple keys on 1-D SparseArray."],"tags":["pandas","sparse","sparse-array","indexing","ellipsis"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}