pandas-dev/pandas · error · ValueError

to_concat must have the same dtype

Error message

to_concat must have the same dtype

What it means

_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.

Source

Thrown at pandas/core/arrays/_mixins.py:268

    def _concat_same_type(
        cls,
        to_concat: Sequence[Self],
        axis: AxisInt = 0,
    ) -> Self:
        """
        Concatenate multiple arrays of this dtype.

        Parameters
        ----------
        to_concat : sequence of this type

        Returns
        -------
        ExtensionArray
        """
        if not lib.dtypes_all_equal([x.dtype for x in to_concat]):
            dtypes = {str(x.dtype) for x in to_concat}
            raise ValueError("to_concat must have the same dtype", dtypes)

        return super()._concat_same_type(to_concat, axis=axis)

    def searchsorted(
        self,
        value: NumpyValueArrayLike | ExtensionArray,
        side: Literal["left", "right"] = "left",
        sorter: NumpySorter | None = None,
    ) -> npt.NDArray[np.intp] | np.intp:
        """
        Find indices where elements should be inserted to maintain order.

        Find the indices into a sorted array `self` (a) such that, if the
        corresponding elements in `value` were inserted before the indices,
        the order of `self` would be preserved.

        Assuming that `self` is sorted:

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Cast inputs to a common dtype before concat: s1.astype(s2.dtype).
  2. For datetimes, normalize the timezone; for categoricals, use pandas.api.types.union_categoricals.
  3. If heterogeneity is intentional, cast to object or a common base dtype.

Example fix

// before
pd.concat([s_utc, s_cet])
// after
pd.concat([s_utc, s_cet.astype(s_utc.dtype)])
Defensive patterns

Strategy: validation

Validate before calling

def concat_same_dtype(series_list):
    dtypes = {str(s.dtype) for s in series_list}
    if len(dtypes) > 1:
        target = series_list[0].dtype
        series_list = [s.astype(target) for s in series_list]
    return pd.concat(series_list)

Prevention

When it happens

Trigger: 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].

Common situations: Merging columns with different timezones, mismatched categorical categories, or pyarrow columns of different value types after schema evolution.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/94d6465b17f8bf37. Report an issue: GitHub.