{"record":{"id":"94d6465b17f8bf37","repo":"pandas-dev/pandas","slug":"to-concat-must-have-the-same-dtype","errorCode":null,"errorMessage":"to_concat must have the same dtype","messagePattern":"to_concat must have the same dtype","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/_mixins.py","lineNumber":268,"sourceCode":"    def _concat_same_type(\n        cls,\n        to_concat: Sequence[Self],\n        axis: AxisInt = 0,\n    ) -> Self:\n        \"\"\"\n        Concatenate multiple arrays of this dtype.\n\n        Parameters\n        ----------\n        to_concat : sequence of this type\n\n        Returns\n        -------\n        ExtensionArray\n        \"\"\"\n        if not lib.dtypes_all_equal([x.dtype for x in to_concat]):\n            dtypes = {str(x.dtype) for x in to_concat}\n            raise ValueError(\"to_concat must have the same dtype\", dtypes)\n\n        return super()._concat_same_type(to_concat, axis=axis)\n\n    def searchsorted(\n        self,\n        value: NumpyValueArrayLike | ExtensionArray,\n        side: Literal[\"left\", \"right\"] = \"left\",\n        sorter: NumpySorter | None = None,\n    ) -> npt.NDArray[np.intp] | np.intp:\n        \"\"\"\n        Find indices where elements should be inserted to maintain order.\n\n        Find the indices into a sorted array `self` (a) such that, if the\n        corresponding elements in `value` were inserted before the indices,\n        the order of `self` would be preserved.\n\n        Assuming that `self` is sorted:\n","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/_mixins.py#L250-L286","documentation":"_concat_same_type requires all input extension arrays to share the exact same dtype (including metadata like timezone, period freq, or pyarrow value type). The per-type fast concatenation path can only be used when dtypes match; otherwise pandas raises ValueError listing the distinct dtypes found.","triggerScenarios":"pd.concat([s1, s2]) where the underlying extension dtypes differ: datetime64[ns, UTC] vs datetime64[ns, CET]; two Categoricals with different category sets; int32[pyarrow] vs int64[pyarrow].","commonSituations":"Merging columns with different timezones, mismatched categorical categories, or pyarrow columns of different value types after schema evolution.","solutions":["Cast inputs to a common dtype before concat: s1.astype(s2.dtype).","For datetimes, normalize the timezone; for categoricals, use pandas.api.types.union_categoricals.","If heterogeneity is intentional, cast to object or a common base dtype."],"exampleFix":"// before\npd.concat([s_utc, s_cet])\n// after\npd.concat([s_utc, s_cet.astype(s_utc.dtype)])","handlingStrategy":"validation","validationCode":"def concat_same_dtype(series_list):\n    dtypes = {str(s.dtype) for s in series_list}\n    if len(dtypes) > 1:\n        target = series_list[0].dtype\n        series_list = [s.astype(target) for s in series_list]\n    return pd.concat(series_list)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align extension dtype metadata (tz, categories, pyarrow value type) before concat","Use union_categoricals for categorical merging"],"tags":["concat","dtype","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}