Commit ·
00aa61d
1
Parent(s): a49dc1b
[NOTICKET][doc] fix aggregate count operation when value_col is not specified
Browse files
src/query/executors/tabular.py
CHANGED
|
@@ -178,9 +178,15 @@ def _apply_operation(df: pd.DataFrame, op: TabularOperation, limit: int) -> pd.D
|
|
| 178 |
raise ValueError(f"sort requires sort_col, got {op}")
|
| 179 |
return df.sort_values(op.sort_col, ascending=op.ascending).head(limit)
|
| 180 |
elif op.operation == "aggregate":
|
| 181 |
-
if not op.
|
| 182 |
-
raise ValueError(f"aggregate requires
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
value = getattr(df[op.value_col], funcs[op.agg_func])()
|
| 185 |
return pd.DataFrame([{op.value_col: value, "operation": op.agg_func}])
|
| 186 |
else: # "raw"
|
|
|
|
| 178 |
raise ValueError(f"sort requires sort_col, got {op}")
|
| 179 |
return df.sort_values(op.sort_col, ascending=op.ascending).head(limit)
|
| 180 |
elif op.operation == "aggregate":
|
| 181 |
+
if not op.agg_func:
|
| 182 |
+
raise ValueError(f"aggregate requires agg_func, got {op}")
|
| 183 |
+
if op.agg_func == "count":
|
| 184 |
+
if not op.value_col:
|
| 185 |
+
return pd.DataFrame([{"column_name": c, "dtype": str(df[c].dtype)} for c in df.columns])
|
| 186 |
+
return pd.DataFrame([{"count": int(df[op.value_col].count()), "operation": "count"}])
|
| 187 |
+
if not op.value_col:
|
| 188 |
+
raise ValueError(f"aggregate requires value_col for {op.agg_func}, got {op}")
|
| 189 |
+
funcs = {"sum": "sum", "avg": "mean", "min": "min", "max": "max"}
|
| 190 |
value = getattr(df[op.value_col], funcs[op.agg_func])()
|
| 191 |
return pd.DataFrame([{op.value_col: value, "operation": op.agg_func}])
|
| 192 |
else: # "raw"
|