code: def test_from_dict_with_scalars() -> None:
      # one or more valid arrays, with some scalars (inc. None)
      df1 = pl.DataFrame(
          {
              "key": ["aa", "bb", "cc"],
              "misc": "xyz",
              "other": None,
              "value": 0,
          }
      )
      assert df1.to_dict(as_series=False) == {
          "key": ["aa", "bb", "cc"],
          "misc": ["xyz", "xyz", "xyz"],
          "other": [None, None, None],
          "value": [0, 0, 0],
      }
  
      # edge-case: all scalars
      df2 = pl.DataFrame(
          {"key": "aa", "misc": "xyz", "other": None, "value": 0}
      )
      assert df2.to_dict(as_series=False) == {
          "key": ["aa"],
          "misc": ["xyz"],
          "other": [None],
          "value": [0],
      }
  
      # edge-case: single unsized generator
      df3 = pl.DataFrame({"vals": map(float, [1, 2, 3])})
      assert df3.to_dict(as_series=False) == {"vals": [1.0, 2.0, 3.0]}
  
      # ensure we don't accidentally consume or expand map/range/generator
      # cols, and can properly apply schema dtype/ordering directives
      df4 = pl.DataFrame(
          {
              "key": range(1, 4),
              "misc": (x for x in [4, 5, 6]),
              "other": map(float, [7, 8, 9]),
              "value": {0: "x", 1: "y", 2: "z"}.values(),
          },
          schema={
              "value": pl.String,
              "other": pl.Float32,
              "misc": pl.Int32,
              "key": pl.Int8,
          },
      )
      assert df4.columns == ["value", "other", "misc", "key"]
      assert df4.to_dict(as_series=False) == {
          "value": ["x", "y", "z"],
          "other": [7.0, 8.0, 9.0],
          "misc": [4, 5, 6],
          "key": [1, 2, 3],
      }
      assert df4.schema == {
          "value": pl.String,
          "other": pl.Float32,
          "misc": pl.Int32,
          "key": pl.Int8,
      }
  
      # mixed with struct cols
      for df5 in (
          pl.from_dict(
              {"x": {"b": [1, 3], "c": [2, 4]}, "y": [5, 6], "z": "x"},
              schema_overrides={"y": pl.Int8},
          ),
          pl.from_dict(
              {"x": {"b": [1, 3], "c": [2, 4]}, "y": [5, 6], "z": "x"},
              schema=["x", ("y", pl.Int8), "z"],
          ),
      ):
          assert df5.rows() == [
              ({"b": 1, "c": 2}, 5, "x"),
              ({"b": 3, "c": 4}, 6, "x"),
          ]
          assert df5.schema == {
              "x": pl.Struct(
                  [pl.Field("b", pl.Int64), pl.Field("c", pl.Int64)]
              ),
              "y": pl.Int8,
              "z": pl.String,
          }
  
      # mixed with numpy cols...
      df6 = pl.DataFrame(
          {"x": np.ones(3), "y": np.zeros(3), "z": 1.0},
      )
      assert df6.rows() == [
          (1.0, 0.0, 1.0),
          (1.0, 0.0, 1.0),
          (1.0, 0.0, 1.0),
      ]
  
      # ...and trigger multithreaded load codepath
      df7 = pl.DataFrame(
          {
              "w": np.zeros(1001, dtype=np.uint8),
              "x": np.ones(1001, dtype=np.uint8),
              "y": np.zeros(1001, dtype=np.uint8),
              "z": 1,
          },
          schema_overrides={"z": pl.UInt8},
      )
      assert df7[999:].rows() == [(0, 1, 0, 1), (0, 1, 0, 1)]
      assert df7.schema == {
          "w": pl.UInt8,
          "x": pl.UInt8,
          "y": pl.UInt8,
          "z": pl.UInt8,
      }
  
      # misc generators/iterables
      df9 = pl.DataFrame(
          {
              "a": iter([0, 1, 2]),
              "b": (2, 1, 0).__iter__(),
              "c": (v for v in (0, 0, 0)),
              "d": "x",
          }
      )
      assert df9.rows() == [
          (0, 2, 0, "x"),
          (1, 1, 0, "x"),
          (2, 0, 0, "x"),
      ]
  
file_path: polars/py-polars/tests/unit/dataframe/test_from_dict.py
imports: from __future__ import annotations
  from datetime import date, datetime, time, timedelta
  from typing import Any
  import numpy
  import pytest
  import polars
  from polars.testing import assert_frame_equal
label_desc: Use image node_id 2 for calling a global function with example usage: test_from_dict_with_scalars() without return types