{"record":{"id":"fa5ecc5569bdc4d9","repo":"pandas-dev/pandas","slug":"dtype-self-dtype-does-not-support-operation-q-fa5ecc","errorCode":null,"errorMessage":"dtype '{self.dtype}' does not support operation 'quantile'","messagePattern":"dtype '(.+?)' does not support operation 'quantile'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":3151,"sourceCode":"        Parameters\n        ----------\n        qs : np.ndarray[float64]\n            Quantile(s) to compute.\n        interpolation : {'linear', 'lower', 'higher', 'nearest', 'midpoint'}\n        ids : np.ndarray[np.intp]\n            Group labels.\n        ngroups : int\n        starts : np.ndarray[int64]\n        ends : np.ndarray[int64]\n\n        Returns\n        -------\n        np.ndarray or ExtensionArray\n        \"\"\"\n        from pandas.core.arrays.string_ import StringDtype\n\n        if isinstance(self.dtype, StringDtype) or is_object_dtype(self.dtype):\n            raise TypeError(\n                f\"dtype '{self.dtype}' does not support operation 'quantile'\"\n            )\n        if is_bool_dtype(self.dtype):\n            raise TypeError(\"Cannot use quantile with bool dtype\")\n\n        mask = np.asarray(isna(self))\n        nqs = len(qs)\n\n        if is_integer_dtype(self.dtype) or is_float_dtype(self.dtype):\n            vals = self.to_numpy(dtype=float, na_value=np.nan)\n        else:\n            vals = np.asarray(self)\n\n        inference: np.dtype | None = (\n            np.dtype(np.int64) if is_integer_dtype(self.dtype) else None\n        )\n\n        out = np.empty((ngroups, nqs), dtype=np.float64)","sourceCodeStart":3133,"sourceCodeEnd":3169,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L3133-L3169","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndf.groupby('key')['name'].quantile(0.5)\n// after\ndf.groupby('key')['value'].quantile(0.5)\n// or\ndf['value'] = pd.to_numeric(df['value'], errors='coerce')","handlingStrategy":"validation","validationCode":"numeric_df = df.select_dtypes(include=['number', 'datetime'])\nif df[col].dtype in ('object', 'string'):\n    raise TypeError(f'{col} is not numeric; quantile unsupported')","typeGuard":"def is_quantile_supported(s) -> bool:\n    from pandas.api.types import is_string_dtype, is_object_dtype, is_bool_dtype\n    return not (is_string_dtype(s) or is_object_dtype(s) or is_bool_dtype(s))","tryCatchPattern":"try:\n    df.groupby('key')[col].quantile(q)\nexcept TypeError as e:\n    if 'does not support operation' in str(e):\n        # skip non-numeric columns\n        ...","preventionTips":["Always subset to numeric columns before groupby quantile.","Centralize quantile logic behind a helper that filters dtypes."],"tags":["groupby","quantile","dtype","string","extension-array"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}