{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/_arrow_string_mixins.py#L148-L184","documentation":"Raised by the pyarrow-backed string `.str.pad()` when `side` is not 'left', 'right', or 'both'. The method maps each side to a distinct pyarrow compute kernel (utf8_lpad / utf8_rpad / utf8_center); an unknown side has no kernel and is rejected up front. This also affects str.center/str.ljust/str.rjust, which delegate to _str_pad. It is a hard ValueError on string[pyarrow] Series.","triggerScenarios":"Calling s.str.pad(width, side='Left'), side='middle', side=None, or passing fillchar into the side slot positionally, on a Series whose dtype is string[pyarrow] or str backed by pyarrow.","commonSituations":"Case-sensitivity typos ('Left' vs 'left'), localized side strings read from config, or argument-order mistakes when calling pad(width, side, fillchar) positionally.","solutions":["Pass side as one of the lowercase strings 'left', 'right', 'both'.","If you used str.center/str.ljust/str.rjust, prefer those over calling _str_pad directly with a custom side.","Whitelist-validate side against {'left','right','both'} before the call when it comes from user/config input."],"exampleFix":"// before\ns.str.pad(5, \"Left\")\n// after\ns.str.pad(5, \"left\")","handlingStrategy":"validation","validationCode":"def safe_pad(s, width, side=\"left\", fillchar=\" \"):\n    if side not in (\"left\", \"right\", \"both\"):\n        raise ValueError(f\"side must be one of left/right/both, got {side!r}\")\n    return s.str.pad(width, side=side, fillchar=fillchar)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize side to lowercase before passing","Prefer str.ljust/str.rjust/str.center which infer side for you"],"tags":["validation","string","pyarrow","argument-error"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}