code: def test_ternary_none_struct() -> None:
      ignore_nulls = False
  
      def map_expr(name: str) -> pl.Expr:
          return (
              pl.when(ignore_nulls or pl.col(name).null_count() == 0)
              .then(
                  pl.struct(
                      [
                          pl.sum(name).alias("sum"),
                          (
                              pl.count() - pl.col(name).null_count()
                          ).alias("count"),
                      ]
                  ),
              )
              .otherwise(None)
          ).alias("out")
  
      assert (
          pl.DataFrame(
              {"groups": [1, 2, 3, 4], "values": [None, None, 1, 2]}
          )
          .group_by("groups", maintain_order=True)
          .agg([map_expr("values")])
      ).to_dict(as_series=False) == {
          "groups": [1, 2, 3, 4],
          "out": [
              {"sum": None, "count": None},
              {"sum": None, "count": None},
              {"sum": 1, "count": 1},
              {"sum": 2, "count": 1},
          ],
      }
  
imports: from __future__ import annotations
  from datetime import datetime, timedelta
  from typing import Any
  import numpy
  import pandas
  import polars
  from polars.testing import assert_frame_equal
label_desc: Use image node_id 13 for calling a global function with example usage: test_ternary_none_struct() and returns: pl