code: def test_aggregate(custom_data, unittest):
      from dtale.views import build_dtypes_state
  
      global_state.clear_store()
      with app.test_client() as c:
          data = {c.port: custom_data}
          dtypes = {c.port: build_dtypes_state(custom_data)}
          settings = {c.port: {}}
  
          build_data_inst(data)
          build_dtypes(dtypes)
          build_settings(settings)
          reshape_cfg = dict(
              index="date",
              agg=dict(
                  type="col",
                  cols={"Col0": ["sum", "mean"], "Col1": ["count"]},
              ),
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          new_key = str(c.port + 1)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              ["date", "Col0 sum", "Col0 mean", "Col1 count"],
          )
          assert len(global_state.get_data(new_key)) == 365
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
          reshape_cfg = dict(
              index="date",
              agg=dict(type="func", func="mean", cols=["Col0", "Col1"]),
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              ["date", "Col0", "Col1"],
          )
          assert len(global_state.get_data(new_key)) == 365
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
          reshape_cfg = dict(
              index="date",
              agg=dict(
                  type="func", func="gmean", cols=["Col0", "Col1"]
              ),
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              ["date", "Col0", "Col1"],
          )
          assert len(global_state.get_data(new_key)) == 365
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
          reshape_cfg = dict(
              index=None,
              agg=dict(
                  type="func", func="gmean", cols=["Col0", "Col1"]
              ),
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              ["Col0", "Col1"],
          )
          assert len(global_state.get_data(new_key)) == 1
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
          reshape_cfg = dict(
              index="date",
              agg=dict(type="func", func="mean", dropna=True),
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              [
                  "date",
                  "security_id",
                  "int_val",
                  "Col0",
                  "Col1",
                  "Col2",
                  "bool_val",
              ],
          )
          assert len(global_state.get_data(new_key)) == 365
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
          reshape_cfg = dict(
              index="bool_val",
              agg=dict(type="func", func="count_pct"),
              dropna=False,
          )
          resp = c.get(
              "/dtale/reshape/{}".format(c.port),
              query_string=dict(
                  output="new",
                  type="aggregate",
                  cfg=json.dumps(reshape_cfg),
              ),
          )
          response_data = json.loads(resp.data)
          assert response_data["data_id"] == new_key
          assert len(global_state.keys()) == 2
          unittest.assertEqual(
              [d["name"] for d in global_state.get_dtypes(new_key)],
              ["bool_val", "Count", "Percentage"],
          )
          assert (
              sum(global_state.get_data(new_key)["Percentage"].values)
              == 100
          )
          assert (
              global_state.get_settings(new_key).get("startup_code")
              is not None
          )
          c.get(
              "/dtale/cleanup-datasets",
              query_string=dict(dataIds=new_key),
          )
  
file_path: dtale/tests/dtale/test_reshapers.py
imports: import json
  import pandas
  import numpy
  import pytest
  import dtale.global_state
  from tests.dtale import build_data_inst, build_settings, build_dtypes
  from tests.dtale.test_views import app
label_desc: Use image node_id 2 for calling a global function with example usage: test_aggregate(custom_data, unittest) without return types