{"record":{"id":"b31eb84ac7c3142c","repo":"pandas-dev/pandas","slug":"lengths-of-operands-do-not-match-len-self","errorCode":null,"errorMessage":"Lengths of operands do not match: {len(self)} != {len(other)}","messagePattern":"Lengths of operands do not match: (.+?) != (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":1290,"sourceCode":"                f\"'{op_name}' operations between boolean dtype and {self.dtype} are \"\n                \"deprecated and will raise in a future version. Explicitly \"\n                \"cast the strings to a boolean dtype before operating instead.\",\n                Pandas4Warning,\n                stacklevel=find_stack_level(),\n            )\n            return op(other, self.astype(bool))\n        else:\n            return self._evaluate_op_method(other, op, ARROW_LOGICAL_FUNCS)\n\n    def _str_arith_method_object_fallback(\n        self, other, op\n    ) -> Self | npt.NDArray[np.object_]:\n        mask = isna(self) | isna(other)\n        valid = ~mask\n\n        if is_list_like(other):\n            if len(other) != len(self):\n                raise ValueError(\n                    f\"Lengths of operands do not match: {len(self)} != {len(other)}\"\n                )\n            if not is_array_like_deprecate_non_pandas(other):\n                other = np.asarray(other)\n            other = other[valid]\n\n        result = np.empty(len(self), dtype=object)\n        result[mask] = self.dtype.na_value\n        result[valid] = op(np.asarray(self, dtype=object)[valid], other)\n\n        if not lib.is_string_array(result, skipna=True):\n            return result\n        return type(self)._from_sequence(result, dtype=self.dtype)\n\n    def _arith_method(self, other, op) -> Self | npt.NDArray[np.object_]:\n        if isinstance(other, BaseOffset) and pa.types.is_date(self._pa_array.type):\n            # Cast date32/date64 → timestamp, apply offset via DatetimeArray, cast back\n            ts_array = type(self)(self._pa_array.cast(pa.timestamp(\"us\")))","sourceCodeStart":1272,"sourceCodeEnd":1308,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L1272-L1308","documentation":"Raised by _str_arith_method_object_fallback when `other` is list-like but its length differs from len(self). This fallback path emulates string arithmetic through object dtype, and it requires the operands to be broadcastable; a length mismatch is a programmer error, not a missing-feature error.","triggerScenarios":"string_array + list_of_different_length; s + other_series where Indexes/lengths differ and pandas did not align (this fallback is reached after pyarrow raises ArrowInvalid/TypeError); passing a tuple or 2-D array as the other operand.","commonSituations":"Manual elementwise operations bypassing Series alignment; feeding a raw list whose length was computed independently; off-by-one in generating the operand list; numpy broadcasting assumptions that do not hold for object fallback.","solutions":["Ensure len(other) == len(arr) before operating, or wrap in a Series so pandas aligns on the index.","Use a scalar operand for uniform operations.","Broadcast explicitly: np.broadcast_to(other, len(arr)).","Align indexes first if both are Series: s1.align(s2)."],"exampleFix":"# before\ns = pd.Series(['a', 'b', 'c'], dtype=\"string[pyarrow]\")\ns + pd.array(['x', 'y'], dtype=\"string[pyarrow]\")  # raises ValueError\n\n# after\ns + pd.array(['x', 'y', 'z'], dtype=\"string[pyarrow]\")","handlingStrategy":"validation","validationCode":"def assert_same_length(a, b):\n    la, lb = len(a), len(b)\n    if la != lb:\n        raise ValueError(f'Length mismatch: {la} != {lb}')\n    return True","typeGuard":"from pandas.api.types import is_list_like\n\ndef is_broadcastable(other, target_len: int) -> bool:\n    return not is_list_like(other) or len(other) == target_len","tryCatchPattern":null,"preventionTips":["Align indexes via Series before elementwise operations.","Validate len(other) == len(arr) before fallback arithmetic.","Prefer scalar operands for uniform operations."],"tags":["arithmetic","string","length-mismatch","validation","fallback"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}