{"record":{"id":"8fdc20005d7b61a6","repo":"pandas-dev/pandas","slug":"invalid-side-side-side-must-be-one-of-left","errorCode":null,"errorMessage":"Invalid side: {side}. Side must be one of 'left', 'right', 'both'","messagePattern":"Invalid side: (.+?)\\. Side must be one of 'left', 'right', 'both'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/_arrow_string_mixins.py","lineNumber":166,"sourceCode":"            pa_pad = pc.utf8_lpad\n        elif side == \"right\":\n            pa_pad = pc.utf8_rpad\n        elif side == \"both\":\n            if pa_version_under17p0:\n                # GH#59624 fall back to object dtype\n                from pandas import array\n\n                obj_arr = self.astype(object, copy=False)  # type: ignore[attr-defined]\n                obj = array(obj_arr, dtype=object)\n                result = obj._str_pad(width, side, fillchar)  # type: ignore[attr-defined]\n                return type(self)._from_sequence(result, dtype=self.dtype)  # type: ignore[attr-defined]\n            else:\n                # GH#54792\n                # https://github.com/apache/arrow/issues/15053#issuecomment-2317032347\n                lean_left = (width % 2) == 0\n                pa_pad = partial(pc.utf8_center, lean_left_on_odd_padding=lean_left)\n        else:\n            raise ValueError(\n                f\"Invalid side: {side}. Side must be one of 'left', 'right', 'both'\"\n            )\n        return self._from_pyarrow_array(\n            pa_pad(self._pa_array, width=width, padding=fillchar)\n        )\n\n    def _str_zfill(self, width: int) -> Self:\n        if pa_version_under21p0:\n            predicate = lambda val: val.zfill(width)\n            result = self._apply_elementwise(predicate)\n            return self._from_pyarrow_array(pa.chunked_array(result))\n        return self._from_pyarrow_array(pc.utf8_zfill(self._pa_array, width))\n\n    def _str_normalize(self, form: Literal[\"NFC\", \"NFD\", \"NFKC\", \"NFKD\"]) -> Self:\n        if form not in (\"NFC\", \"NFD\", \"NFKC\", \"NFKD\"):\n            raise ValueError(\"invalid normalization form\")\n        if form in (\"NFC\", \"NFKC\"):\n            # GH#64359 pc.utf8_normalize only decomposes; it skips the canonical","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/_arrow_string_mixins.py#L148-L184","documentation":"ValueError raised in _str_pad of the ArrowStringArray mixin when the side argument is not one of 'left', 'right', or 'both'. The pyarrow backend uses 'both' for center-padding; 'center' is not accepted.","triggerScenarios":"s.str.pad(width=10, side='center') on a pyarrow-backed string Series (dtype StringDtype(storage='pyarrow')).","commonSituations":"Code that worked on object dtype strings and used 'center' verbatim; users assuming pandas mirrors Python's str.center naming.","solutions":["Use side='both' for center padding: s.str.pad(10, side='both').","Use the higher-level s.str.center(10) which maps to side='both' internally.","Confirm the Series dtype; the same call works on object dtype but pyarrow enforces the documented enum."],"exampleFix":"# before\ns.str.pad(10, side='center')\n# after\ns.str.center(10)  # or s.str.pad(10, side='both')","handlingStrategy":"validation","validationCode":"VALID_SIDES = {'left', 'right', 'both'}\ndef safe_pad(s, width, side, fillchar=' '):\n    if side not in VALID_SIDES:\n        side = 'both' if side == 'center' else 'left'\n    return s.str.pad(width, side=side, fillchar=fillchar)","typeGuard":null,"tryCatchPattern":"try:\n    s.str.pad(10, side=side)\nexcept ValueError as e:\n    if 'Invalid side' in str(e):\n        s.str.center(10)  # map center->both\n    else:\n        raise","preventionTips":["Use s.str.center / s.str.ljust / s.str.rjust helpers which avoid the side enum.","Validate side against {'left','right','both'} before calling str.pad."],"tags":["strings","pyarrow","str-pad","argument"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}