{"id":"fc7f318345da2fed","repo":"redis/redis-py","slug":"excludeempty-is-not-allowed-with-groupby","errorCode":null,"errorMessage":"EXCLUDEEMPTY is not allowed with GROUPBY","messagePattern":"EXCLUDEEMPTY is not allowed with GROUPBY","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/timeseries/commands.py","lineNumber":1424,"sourceCode":"        reduce: str | None,\n        select_labels: List[str] | None,\n        align: int | str | None,\n        latest: bool | None,\n        bucket_timestamp: str | None,\n        empty: bool | None,\n        exclude_empty: bool | None,\n    ):\n        \"\"\"Create TS.MRANGE and TS.MREVRANGE arguments.\"\"\"\n        if (\n            groupby is not None\n            and isinstance(aggregation_type, list)\n            and len(aggregation_type) > 1\n        ):\n            raise DataError(\n                \"GROUPBY is not allowed when multiple aggregators are specified\"\n            )\n        if exclude_empty and groupby is not None:\n            raise DataError(\"EXCLUDEEMPTY is not allowed with GROUPBY\")\n        params: list[EncodableT] = [from_time, to_time]\n        self._append_latest(params, latest)\n        self._append_filer_by_ts(params, filter_by_ts)\n        self._append_filer_by_value(params, filter_by_min_value, filter_by_max_value)\n        self._append_with_labels(params, with_labels, select_labels)\n        self._append_count(params, count)\n        self._append_align(params, align)\n        self._append_aggregation(params, aggregation_type, bucket_size_msec)\n        self._append_bucket_timestamp(params, bucket_timestamp)\n        self._append_empty(params, empty)\n        self._append_exclude_empty(params, exclude_empty)\n        params.extend([\"FILTER\"])\n        params += filters\n        self._append_groupby_reduce(params, groupby, reduce)\n        return params\n\n    @overload\n    def mrange(","sourceCodeStart":1406,"sourceCodeEnd":1442,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/timeseries/commands.py#L1406-L1442","documentation":"Raised by the TS.MRANGE/TS.MREVRANGE parameter builder when both exclude_empty=True and groupby are set. EXCLUDEEMPTY filters out empty series before grouping, which conflicts with GROUPBY semantics (it would drop groups). The library rejects the combination up front.","triggerScenarios":"client.ts().mrange('-', '+', filters=f, groupby='region', reduce='sum', exclude_empty=True).","commonSituations":"Adding EXCLUDEEMPTY to reduce noise while also grouping; copying options from a non-grouped query into a grouped one; enabling both via a shared config dict.","solutions":["Drop exclude_empty when using GROUPBY: set exclude_empty=False (the default).","If you must exclude empty series, pre-filter the series via a TS.QUERYINDEX/QUERYLABELS lookup instead of EXCLUDEEMPTY.","Keep GROUPBY and accept that empty groups may appear."],"exampleFix":"// before\nclient.ts().mrange('-', '+', filters=f, groupby='region', reduce='sum', exclude_empty=True)\n// after\nclient.ts().mrange('-', '+', filters=f, groupby='region', reduce='sum', exclude_empty=False)","handlingStrategy":"validation","validationCode":"def normalize_mrange_opts(groupby, exclude_empty):\n    if groupby is not None and exclude_empty:\n        return groupby, False  # drop EXCLUDEEMPTY when grouping\n    return groupby, exclude_empty","typeGuard":"def groupby_exclude_empty_compatible(groupby, exclude_empty) -> bool:\n    return not (exclude_empty and groupby is not None)","tryCatchPattern":"try:\n    client.ts().mrange('-', '+', filters=f, groupby=g, reduce=r, exclude_empty=ee)\nexcept Exception as e:\n    if 'EXCLUDEEMPTY' in str(e):\n        client.ts().mrange('-', '+', filters=f, groupby=g, reduce=r, exclude_empty=False)\n    else:\n        raise","preventionTips":["Never combine exclude_empty=True with groupby.","Pre-filter empty series via QUERYINDEX instead of EXCLUDEEMPTY when grouping.","Enforce mutual exclusion in option builders."],"tags":["redistimeseries","timeseries","mrange","groupby","exclude-empty","argument-error"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}