mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix: eliminate cartesian product columns in pivot operator (#15975)
* fix: eliminate cartesian product columns in pivot operator * wip * wip * minor tip
This commit is contained in:
@@ -20,7 +20,8 @@ from importlib.util import find_spec
|
||||
import math
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from pandas import DataFrame, Series, Timestamp
|
||||
import numpy as np
|
||||
from pandas import DataFrame, Series, Timestamp, to_datetime
|
||||
import pytest
|
||||
|
||||
from superset.exceptions import QueryObjectValidationError
|
||||
@@ -256,6 +257,26 @@ class TestPostProcessing(SupersetTestCase):
|
||||
aggregates={"idx_nulls": {}},
|
||||
)
|
||||
|
||||
def test_pivot_eliminate_cartesian_product_columns(self):
|
||||
mock_df = DataFrame(
|
||||
{
|
||||
"dttm": to_datetime(["2019-01-01", "2019-01-01"]),
|
||||
"a": [0, 1],
|
||||
"b": [0, 1],
|
||||
"metric": [9, np.NAN],
|
||||
}
|
||||
)
|
||||
|
||||
df = proc.pivot(
|
||||
df=mock_df,
|
||||
index=["dttm"],
|
||||
columns=["a", "b"],
|
||||
aggregates={"metric": {"operator": "mean"}},
|
||||
drop_missing_columns=False,
|
||||
)
|
||||
self.assertEqual(list(df.columns), ["dttm", "0, 0", "1, 1"])
|
||||
self.assertTrue(np.isnan(df["1, 1"][0]))
|
||||
|
||||
def test_aggregate(self):
|
||||
aggregates = {
|
||||
"asc sum": {"column": "asc_idx", "operator": "sum"},
|
||||
|
||||
Reference in New Issue
Block a user