pandas-dev/pandas · error · TypeError

dtype '{self.dtype}' does not support operation 'quantile'

Error message

dtype '{self.dtype}' does not support operation 'quantile'

What it means

ExtensionArray._groupby_quantile (base.py:3151) refuses quantile computation on string or object dtypes with TypeError, because quantiles require ordering on a numeric (or otherwise rankable) domain. Strings have no meaningful interpolation between quantile boundaries.

Source

Thrown at pandas/core/arrays/base.py:3151

        Parameters
        ----------
        qs : np.ndarray[float64]
            Quantile(s) to compute.
        interpolation : {'linear', 'lower', 'higher', 'nearest', 'midpoint'}
        ids : np.ndarray[np.intp]
            Group labels.
        ngroups : int
        starts : np.ndarray[int64]
        ends : np.ndarray[int64]

        Returns
        -------
        np.ndarray or ExtensionArray
        """
        from pandas.core.arrays.string_ import StringDtype

        if isinstance(self.dtype, StringDtype) or is_object_dtype(self.dtype):
            raise TypeError(
                f"dtype '{self.dtype}' does not support operation 'quantile'"
            )
        if is_bool_dtype(self.dtype):
            raise TypeError("Cannot use quantile with bool dtype")

        mask = np.asarray(isna(self))
        nqs = len(qs)

        if is_integer_dtype(self.dtype) or is_float_dtype(self.dtype):
            vals = self.to_numpy(dtype=float, na_value=np.nan)
        else:
            vals = np.asarray(self)

        inference: np.dtype | None = (
            np.dtype(np.int64) if is_integer_dtype(self.dtype) else None
        )

        out = np.empty((ngroups, nqs), dtype=np.float64)

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Restrict quantile to numeric columns: df.groupby(key)[numeric_cols].quantile().
  2. Convert the column to a numeric dtype if the data is actually numeric.
  3. Drop string/object columns before calling groupby().quantile().
  4. Use a different aggregation (e.g. value_counts) for categorical/string groupings.

Example fix

# before
df.groupby("id").quantile()  # raises on string cols

# after
num = df.select_dtypes("number")
num.groupby(df["id"]).quantile()
Defensive patterns

Strategy: validation

Validate before calling

def safe_groupby_quantile(df, key, q):
    import pandas as pd
    num = df.select_dtypes("number")
    return num.groupby(df[key]).quantile(q)

Type guard

def is_quantile_supported(dtype) -> bool:
    import pandas as pd
    return pd.api.types.is_numeric_dtype(dtype) and not pd.api.types.is_bool_dtype(dtype)

Try / catch

try:
    df.groupby("id").quantile()
except TypeError as e:
    if "does not support operation 'quantile'" in str(e):
        df.select_dtypes("number").groupby(df["id"]).quantile()
    else:
        raise

Prevention

When it happens

Trigger: Calling df.groupby(key).quantile(...) or SeriesGroupBy.quantile on a 'string' or object-dtype column.

Common situations: Applying df.groupby(...).quantile() across a mixed DataFrame containing string columns; grouping categorical labels and accidentally requesting quantile on them.

Related errors


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