pandas-dev/pandas · error · TypeError
dtype ' ' does not support operation 'quantile
Error message
dtype '{self.dtype}' does not support operation 'quantile' What it means
Raised by ExtensionArray._groupby_quantile when the grouped array has a StringDtype or object dtype. Quantiles are only defined for ordered numeric data, so pandas refuses to compute them over string or opaque-object columns rather than silently producing meaningless results. The error names the offending dtype so you can identify the column.
Solutions
- Exclude non-numeric columns before quantile: df.select_dtypes(include='number').groupby(g).quantile(...).
- Convert the column to numeric first: df['col'] = pd.to_numeric(df['col'], errors='coerce').
- Drop or filter the string/object column from the grouping selection: groupby on a numeric-only subset.
- If you genuinely need positional statistics for strings, use a different aggregation (e.g. first/last/min/max) instead of quantile.
Example fix
// before
df.groupby('key')['name'].quantile(0.5)
// after
df.groupby('key')['value'].quantile(0.5)
// or
df['value'] = pd.to_numeric(df['value'], errors='coerce') Defensive patterns
Strategy: validation
Validate before calling
numeric_df = df.select_dtypes(include=['number', 'datetime'])
if df[col].dtype in ('object', 'string'):
raise TypeError(f'{col} is not numeric; quantile unsupported') Type guard
def is_quantile_supported(s) -> bool:
from pandas.api.types import is_string_dtype, is_object_dtype, is_bool_dtype
return not (is_string_dtype(s) or is_object_dtype(s) or is_bool_dtype(s)) Try / catch
try:
df.groupby('key')[col].quantile(q)
except TypeError as e:
if 'does not support operation' in str(e):
# skip non-numeric columns
... Prevention
- Always subset to numeric columns before groupby quantile.
- Centralize quantile logic behind a helper that filters dtypes.
When it happens
Trigger: Calling df.groupby(...).quantile() (or Series.groupby quantile) on a column whose dtype is 'string', StringDtype, or object. Also reached via .agg('quantile') or named aggregation targeting a string/object column. The check fires before any Cython dispatch.
Common situations: Selecting all numeric columns with a string column accidentally included (e.g. an ID column stored as string); mixed-type DataFrames where groupby picks up object columns; reading CSVs where numeric-looking codes stay as strings; migrating from object dtype to the new 'string' dtype and re-running an existing quantile pipeline.
Related errors
- Cannot use quantile with bool dtype
- Column is backed by an extension array, which is not…
- Default 'empty' implementation is invalid for dtype=
- {dtype}
- dtype ' ' does not support operation
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/fa5ecc5569bdc4d9.
Report an issue: GitHub.
Appendix: 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 3b7651241d)