{"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":"validation","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/base.py#L3133-L3169","documentation":"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.","triggerScenarios":"Calling df.groupby(key).quantile(...) or SeriesGroupBy.quantile on a 'string' or object-dtype column.","commonSituations":"Applying df.groupby(...).quantile() across a mixed DataFrame containing string columns; grouping categorical labels and accidentally requesting quantile on them.","solutions":["Restrict quantile to numeric columns: df.groupby(key)[numeric_cols].quantile().","Convert the column to a numeric dtype if the data is actually numeric.","Drop string/object columns before calling groupby().quantile().","Use a different aggregation (e.g. value_counts) for categorical/string groupings."],"exampleFix":"# before\ndf.groupby(\"id\").quantile()  # raises on string cols\n\n# after\nnum = df.select_dtypes(\"number\")\nnum.groupby(df[\"id\"]).quantile()","handlingStrategy":"validation","validationCode":"def safe_groupby_quantile(df, key, q):\n    import pandas as pd\n    num = df.select_dtypes(\"number\")\n    return num.groupby(df[key]).quantile(q)","typeGuard":"def is_quantile_supported(dtype) -> bool:\n    import pandas as pd\n    return pd.api.types.is_numeric_dtype(dtype) and not pd.api.types.is_bool_dtype(dtype)","tryCatchPattern":"try:\n    df.groupby(\"id\").quantile()\nexcept TypeError as e:\n    if \"does not support operation 'quantile'\" in str(e):\n        df.select_dtypes(\"number\").groupby(df[\"id\"]).quantile()\n    else:\n        raise","preventionTips":["Restrict quantile to numeric columns","Drop string/object columns before groupby quantile","Convert numeric-like strings before quantile"],"tags":["groupby","quantile","string-dtype","object-dtype","dtype-mismatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}