{"record":{"id":"9cd87803f06c0c00","repo":"pytorch/pytorch","slug":"expected-a-dimension-specifyer-but-found-repr-s","errorCode":null,"errorMessage":"expected a dimension specifyer but found {repr(s)}","messagePattern":"expected a dimension specifyer but found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"functorch/dim/__init__.py","lineNumber":738,"sourceCode":"        | list[int | slice | torch.Tensor],\n    ) -> _Tensor:\n        \"\"\"\n        Index tensor using first-class dimensions.\n        \"\"\"\n        from ._dim_entry import _match_levels\n        from ._getsetitem import getsetitem_flat, invoke_getitem\n        from ._wrap import _wrap_dim\n\n        # Helper to check if obj is a dimpack (tuple/list) and extract items\n        def maybe_dimpack(obj: Any, check_first: bool = False) -> tuple[Any, bool]:\n            if isinstance(obj, (tuple, list)):\n                return list(obj), True\n            return None, False\n\n        def parse_dim_entry(s: Any) -> Any:\n            d = _wrap_dim(s, self.ndim, False)\n            if d.is_none():\n                raise TypeError(f\"expected a dimension specifyer but found {repr(s)}\")\n            return d\n\n        # Helper for dimension not present errors\n        def dim_not_present(d: Any) -> None:\n            if d.is_positional():\n                raise TypeError(\n                    f\"dimension {d.position() + self.ndim} not in tensor of {self.ndim} dimensions\"\n                )\n            else:\n                raise TypeError(f\"dimension {repr(d.dim())} not in tensor\")\n\n        dims_list: list[int | Dim] = []\n        indices_list: list[int | slice | torch.Tensor] = []\n\n        lhs_list = isinstance(dims, (tuple, list))\n        rhs_list = isinstance(indices, (tuple, list))\n\n        if lhs_list and rhs_list:","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/pytorch/pytorch/blob/dcd2ecae775af66439b7ede4e7a82540b058c59c/functorch/dim/__init__.py#L720-L756","documentation":"Inside Tensor.index(), each entry of the dims argument is normalized with _wrap_dim; if the result 'is none' (the value could not be interpreted as a positional int or a Dim), TypeError('expected a dimension specifyer but found {s}') is raised. Valid specifyers are ints and Dim objects.","triggerScenarios":"Passing None, a string, a float, a numpy scalar, or other objects as a dimension to tensor.index(...) / the dims part of first-class-dimension indexing, e.g. t.index('batch', 0) or t.index(None, slice(None)).","commonSituations":"Mixing string axis names (pandas/xarray habits) with functorch dims, passing unwrapped numpy ints, or None leaking in from optional config for a dim name.","solutions":["Pass only int positions or Dim objects created by dims()/dimlists()","Convert numpy scalars: t.index(int(np_axis), ...)","For named axes use actual dims: batch = dims(1); t.index(batch, 0)"],"exampleFix":"# before\nout = t.index('batch', 0)  # TypeError: string not a dimension specifyer\n\n# after\nbatch = dims(1)\nout = t.index(batch, 0)","handlingStrategy":"type-guard","validationCode":"from functorch.dim import Dim\nif not isinstance(s, (int, Dim)):\n    raise TypeError(f'dimension specifyer must be int or Dim, got {type(s).__name__}')","typeGuard":"from functorch.dim import Dim\nimport numpy as np\ndef is_dim_specifyer(s) -> bool:\n    if isinstance(s, np.integer):\n        s = int(s)\n    return isinstance(s, (int, Dim)) and not isinstance(s, bool)","tryCatchPattern":null,"preventionTips":["Only pass ints and Dim objects as dims to index()","Convert numpy scalars with int() at the boundary","Do not use string axis names; create real dims with dims()"],"tags":["functorch","tensor-indexing","typeerror","type-validation"],"backgroundTag":null,"analyzedSha":"dcd2ecae775af66439b7ede4e7a82540b058c59c","analyzedAt":"2026-08-14T19:21:26.615Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}