code: def test_chart_infer_types():
      data = pd.DataFrame(
          {
              "x": pd.date_range("2012", periods=10, freq="Y"),
              "y": range(10),
              "c": list("abcabcabca"),
              "s": pd.Categorical(
                  [1, 2] * 5, categories=[2, 1], ordered=True
              ),
          }
      )
  
      def _check_encodings(chart):
          dct = chart.to_dict()
          assert dct["encoding"]["x"]["type"] == "temporal"
          assert dct["encoding"]["x"]["field"] == "x"
          assert dct["encoding"]["y"]["type"] == "quantitative"
          assert dct["encoding"]["y"]["field"] == "y"
          assert dct["encoding"]["color"]["type"] == "nominal"
          assert dct["encoding"]["color"]["field"] == "c"
          assert dct["encoding"]["size"]["type"] == "ordinal"
          assert dct["encoding"]["size"]["field"] == "s"
          assert dct["encoding"]["size"]["sort"] == [2, 1]
          assert dct["encoding"]["tooltip"]["type"] == "ordinal"
          assert dct["encoding"]["tooltip"]["field"] == "s"
          # "sort" should be removed for channels that don't support it
          assert "sort" not in dct["encoding"]["tooltip"]
  
      # Pass field names by keyword
      chart = (
          alt.Chart(data)
          .mark_point()
          .encode(x="x", y="y", color="c", size="s", tooltip="s")
      )
      _check_encodings(chart)
  
      # pass Channel objects by keyword
      chart = (
          alt.Chart(data)
          .mark_point()
          .encode(
              x=alt.X("x"),
              y=alt.Y("y"),
              color=alt.Color("c"),
              size=alt.Size("s"),
              tooltip=alt.Tooltip("s"),
          )
      )
      _check_encodings(chart)
  
      # pass Channel objects by value
      chart = (
          alt.Chart(data)
          .mark_point()
          .encode(
              alt.X("x"),
              alt.Y("y"),
              alt.Color("c"),
              alt.Size("s"),
              alt.Tooltip("s"),
          )
      )
      _check_encodings(chart)
  
      # override default types
      chart = (
          alt.Chart(data)
          .mark_point()
          .encode(
              alt.X("x", type="nominal"),
              alt.Y("y", type="ordinal"),
              alt.Size("s", type="nominal"),
              alt.Tooltip("s", type="nominal"),
          )
      )
      dct = chart.to_dict()
      assert dct["encoding"]["x"]["type"] == "nominal"
      assert dct["encoding"]["y"]["type"] == "ordinal"
      assert dct["encoding"]["size"]["type"] == "nominal"
      assert "sort" not in dct["encoding"]["size"]
      assert dct["encoding"]["tooltip"]["type"] == "nominal"
      assert "sort" not in dct["encoding"]["tooltip"]
  
imports: import io
  import json
  import operator
  import os
  import pathlib
  import tempfile
  import jsonschema
  import pytest
  import pandas
  import altair.vegalite.v5
label_desc: Use image node_id 5 for calling a global function with example usage: test_chart_infer_types() without return types