{"record":{"id":"55f69b74812de448","repo":"pandas-dev/pandas","slug":"only-integers-slices-ellipsis-num","errorCode":null,"errorMessage":"only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices","messagePattern":"only integers, slices \\(`:`\\), ellipsis \\(`\\.\\.\\.`\\), numpy\\.newaxis \\(`None`\\) and integer or boolean arrays are valid indices","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":933,"sourceCode":"                return self.take(item)\n            elif item.dtype.kind == \"b\":\n                return self._from_pyarrow_array(self._pa_array.filter(item))\n            else:\n                raise IndexError(\n                    \"Only integers, slices and integer or \"\n                    \"boolean arrays are valid indices.\"\n                )\n        elif isinstance(item, tuple):\n            item = unpack_tuple_and_ellipses(item)\n\n        if item is Ellipsis:\n            # TODO: should be handled by pyarrow?\n            item = slice(None)\n\n        if is_scalar(item) and not is_integer(item):\n            # e.g. \"foo\" or 2.5\n            # exception message copied from numpy\n            raise IndexError(\n                r\"only integers, slices (`:`), ellipsis (`...`), numpy.newaxis \"\n                r\"(`None`) and integer or boolean arrays are valid indices\"\n            )\n        # We are not an array indexer, so maybe e.g. a slice or integer\n        # indexer. We dispatch to pyarrow.\n        value = self._pa_array[item]\n        if isinstance(value, pa.ChunkedArray):\n            result = self._from_pyarrow_array(value)\n            if getitem_returns_view(self, item):\n                result._readonly = self._readonly\n            return result\n        else:\n            pa_type = self._pa_array.type\n            scalar = value.as_py()\n            if scalar is None:\n                return self._dtype.na_value\n            elif pa.types.is_timestamp(pa_type) and pa_type.unit != \"ns\":\n                # GH 53326","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L915-L951","documentation":"Raised by ArrowExtensionArray.__getitem__ for a scalar indexer that is neither an integer nor something the array/slice/tuple branches handled. The message is intentionally copied from numpy's IndexError. Typical triggers: indexing with a string label, a float like 2.5, or any non-integer scalar.","triggerScenarios":"arr['foo'] on a positional extension array; arr[2.5]; indexing with a python float that 'looks like' an int; indexing with a None that escaped the Ellipsis/None handling; using a pandas Timedelta/Timestamp scalar as a positional indexer.","commonSituations":"Confusing label-based access (.loc) with positional access (.iloc/__getitem__); passing dict keys or column names into an extension array; off-by-one errors producing float positions; legacy code assuming object-dtype indexing semantics.","solutions":["If you meant a label lookup, go through the parent Series/Index: s.loc[label] or s[label].","If you have a float that is mathematically integral, cast: arr[int(idx)].","Validate with is_integer before indexing, or wrap user input with int().","For multi-dimensional style indexing, ensure tuples contain only ints/slices/Ellipsis/None."],"exampleFix":"# before\narr = pd.array([10, 20, 30], dtype=\"int64[pyarrow]\")\narr[1.0]  # raises IndexError\n\n# after\narr[int(1.0)]","handlingStrategy":"type-guard","validationCode":"from pandas.api.types import is_integer\n\ndef safe_scalar_index(arr, item):\n    if is_integer(item):\n        return arr[item]\n    raise TypeError(f'non-integer scalar indexer: {item!r}')","typeGuard":"from numbers import Integral\nfrom pandas.api.types import is_scalar\n\ndef is_integer_scalar(v) -> bool:\n    return is_scalar(v) and isinstance(v, Integral)","tryCatchPattern":null,"preventionTips":["Use Series.loc for label access and reserve raw __getitem__ for integers.","Cast floats to int explicitly: arr[int(idx)].","Reject non-integer scalars at the API boundary."],"tags":["indexing","scalar","type-validation","getitem"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}