code: def test_parse_shorthand():
      def check(s, **kwargs):
          assert parse_shorthand(s) == kwargs
  
      check("")
  
      # Fields alone
      check("foobar", field="foobar")
      check(r"blah\:(fd ", field=r"blah\:(fd ")
  
      # Fields with type
      check("foobar:quantitative", type="quantitative", field="foobar")
      check("foobar:nominal", type="nominal", field="foobar")
      check("foobar:ordinal", type="ordinal", field="foobar")
      check("foobar:temporal", type="temporal", field="foobar")
      check("foobar:geojson", type="geojson", field="foobar")
  
      check("foobar:Q", type="quantitative", field="foobar")
      check("foobar:N", type="nominal", field="foobar")
      check("foobar:O", type="ordinal", field="foobar")
      check("foobar:T", type="temporal", field="foobar")
      check("foobar:G", type="geojson", field="foobar")
  
      # Fields with aggregate and/or type
      check("average(foobar)", field="foobar", aggregate="average")
      check(
          "min(foobar):temporal",
          type="temporal",
          field="foobar",
          aggregate="min",
      )
      check(
          "sum(foobar):Q",
          type="quantitative",
          field="foobar",
          aggregate="sum",
      )
  
      # check that invalid arguments are not split-out
      check("invalid(blah)", field="invalid(blah)")
      check(r"blah\:invalid", field=r"blah\:invalid")
      check(r"invalid(blah)\:invalid", field=r"invalid(blah)\:invalid")
  
      # check parsing in presence of strange characters
      check(
          r"average(a b\:(c\nd):Q",
          aggregate="average",
          field=r"a b\:(c\nd",
          type="quantitative",
      )
  
      # special case: count doesn't need an argument
      check("count()", aggregate="count", type="quantitative")
      check("count():O", aggregate="count", type="ordinal")
  
      # time units:
      check("month(x)", field="x", timeUnit="month", type="temporal")
      check("year(foo):O", field="foo", timeUnit="year", type="ordinal")
      check(
          "date(date):quantitative",
          field="date",
          timeUnit="date",
          type="quantitative",
      )
      check(
          "yearmonthdate(field)",
          field="field",
          timeUnit="yearmonthdate",
          type="temporal",
      )
  
imports: import types
  from packaging.version import Version
  from importlib.metadata import version
  import numpy
  import pandas
  import pytest
  import altair
  from altair.utils.core import parse_shorthand, update_nested, infer_encoding_types
  from altair.utils.core import infer_dtype
label_desc: Use image node_id 2 for calling a global function with example usage: test_parse_shorthand() without return types