{"record":{"id":"8901f6b7b60b69ae","repo":"pandas-dev/pandas","slug":"cannot-use-quantile-with-bool-dtype","errorCode":null,"errorMessage":"Cannot use quantile with bool dtype","messagePattern":"Cannot use quantile with bool dtype","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":3155,"sourceCode":"        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)\n        libgroupby.group_quantile(\n            out,\n            values=vals,\n            mask=mask,  # type: ignore[arg-type]","sourceCodeStart":3137,"sourceCodeEnd":3173,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L3137-L3173","documentation":"Raised by ExtensionArray._groupby_quantile when the grouped array has a boolean dtype. Boolean data has no meaningful ordering for percentile interpolation, so pandas blocks quantile computation explicitly (separate from the string/object check). This guard runs before any numeric conversion of the values.","triggerScenarios":"Calling groupby(...).quantile() on a column of dtype bool or pandas 'boolean' (nullable BooleanArray). Reached through agg({'col': 'quantile'}), SeriesGroupBy.quantile, or describe() on a boolean column inside a groupby.","commonSituations":"Boolean flag columns included in a broad select_dtypes pipeline that happens to capture bools; nullable 'boolean' arrays from pd.array(..., dtype='boolean'); aggregating survey/experiment flag data with a quantile template written for numeric metrics.","solutions":["Filter boolean columns out before calling quantile: select only integer/float dtypes.","Cast the boolean column to int if you treat True=1/False=0: df['col'] = df['col'].astype('Int64').","Use a boolean-appropriate aggregation instead (sum for count of True, mean for proportion True).","Drop the boolean column from the groupby column selection."],"exampleFix":"// before\ndf.groupby('key')['is_active'].quantile(0.5)\n// after\ndf.groupby('key')['is_active'].astype('Int64').quantile(0.5)","handlingStrategy":"validation","validationCode":"from pandas.api.types import is_bool_dtype\nif is_bool_dtype(df[col]):\n    raise TypeError(f'{col} is bool; quantile unsupported')","typeGuard":"def supports_quantile(s) -> bool:\n    from pandas.api.types import is_bool_dtype, is_numeric_dtype\n    return is_numeric_dtype(s) and not is_bool_dtype(s)","tryCatchPattern":"try:\n    df.groupby('key')[col].quantile(q)\nexcept TypeError as e:\n    if 'bool dtype' in str(e):\n        ...","preventionTips":["Filter out bool columns before quantile pipelines.","If you treat bool as 0/1, cast to Int64 first."],"tags":["groupby","quantile","boolean","dtype","extension-array"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}