{"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":"validation","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/base.py#L3137-L3173","documentation":"ExtensionArray._groupby_quantile (base.py:3155) rejects boolean dtype with TypeError. Although booleans are technically 0/1, computing interpolation-based quantiles on a binary domain is statistically meaningless, so pandas forbids it explicitly.","triggerScenarios":"Calling df.groupby(key).quantile(...) or SeriesGroupBy.quantile on a 'boolean' (nullable bool) column, or a plain bool column routed through this path.","commonSituations":"Running groupby().quantile() over an entire DataFrame that includes a boolean flag column; flag/indicator columns inadvertently included in numeric aggregation pipelines.","solutions":["Exclude boolean columns before quantile: operate on numeric columns only.","Cast the boolean column to int if a 0/1 quantile is genuinely wanted: s.astype('Int64').groupby(key).quantile().","Drop the boolean column from the groupby quantile target.","Use a boolean-appropriate aggregation (any/all/sum-of-true)."],"exampleFix":"# before\ndf.groupby(\"id\")[\"flag\"].quantile()  # flag is 'boolean' -> raises\n\n# after\ndf[\"flag\"].astype(\"Int64\").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\")[\"flag\"].quantile()\nexcept TypeError as e:\n    if \"bool dtype\" in str(e):\n        df[\"flag\"].astype(\"Int64\").groupby(df[\"id\"]).quantile()\n    else:\n        raise","preventionTips":["Exclude boolean columns before quantile","Cast bool to Int64 when 0/1 quantile is wanted","Use select_dtypes(include='number') for quantile pipelines"],"tags":["groupby","quantile","boolean","dtype-mismatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}