code: def test_asof_join_nearest_by() -> None:
      # Generic join_asof
      df1 = pl.DataFrame(
          {
              "asof_key": [-1, 1, 2, 6, 1],
              "group": [1, 1, 1, 2, 2],
              "a": [1, 2, 3, 2, 5],
          }
      ).sort(by=["group", "asof_key"])
  
      df2 = pl.DataFrame(
          {
              "asof_key": [-1, 2, 5, 1],
              "group": [1, 1, 2, 2],
              "b": [1, 2, 3, 4],
          }
      ).sort(by=["group", "asof_key"])
  
      expected = pl.DataFrame(
          {
              "asof_key": [-1, 1, 2, 6, 1],
              "group": [1, 1, 1, 2, 2],
              "a": [1, 2, 3, 5, 2],
              "b": [1, 2, 2, 4, 3],
          }
      ).sort(by=["group", "asof_key"])
  
      # Edge case: last item of right matches multiples on left
      df1 = pl.DataFrame(
          {
              "asof_key": [9, 9, 10, 10, 10],
              "group": [1, 1, 1, 2, 2],
              "a": [1, 2, 3, 2, 5],
          }
      ).sort(by=["group", "asof_key"])
  
      df2 = pl.DataFrame(
          {
              "asof_key": [-1, 1, 1, 10],
              "group": [1, 1, 2, 2],
              "b": [1, 2, 3, 4],
          }
      ).sort(by=["group", "asof_key"])
  
      expected = pl.DataFrame(
          {
              "asof_key": [9, 9, 10, 10, 10],
              "group": [1, 1, 1, 2, 2],
              "a": [1, 2, 3, 2, 5],
              "b": [2, 2, 2, 4, 4],
          }
      )
  
      out = df1.join_asof(
          df2, on="asof_key", by="group", strategy="nearest"
      )
      assert_frame_equal(out, expected)
  
      a = pl.DataFrame(
          {
              "code": [676, 35, 676, 676, 676],
              "time": [364360, 364370, 364380, 365400, 367440],
          }
      )
      b = pl.DataFrame(
          {
              "code": [676, 676, 35, 676, 676],
              "time": [364000, 365000, 365000, 366000, 367000],
              "price": [1.0, 2.0, 50, 3.0, None],
          }
      )
  
      expected = pl.DataFrame(
          {
              "code": [676, 35, 676, 676, 676],
              "time": [364360, 364370, 364380, 365400, 367440],
              "price": [1.0, 50.0, 1.0, 2.0, None],
          }
      )
  
      out = a.join_asof(b, by="code", on="time", strategy="nearest")
      assert_frame_equal(out, expected)
  
      # last item is closest match
      df1 = pl.DataFrame(
          {
              "a": [1, 1, 1],
              "asof_key_left": [10.00001, 20.0, 30.0],
          }
      ).set_sorted("asof_key_left")
      df2 = pl.DataFrame(
          {
              "a": [1, 1, 1],
              "asof_key_right": [10.00001, 20.0001, 29.0],
          }
      ).set_sorted("asof_key_right")
      out = df1.join_asof(
          df2,
          left_on="asof_key_left",
          right_on="asof_key_right",
          by="a",
          strategy="nearest",
      )
      expected = pl.DataFrame(
          {
              "a": [1, 1, 1],
              "asof_key_left": [10.00001, 20.0, 30.0],
              "asof_key_right": [10.00001, 20.0001, 29.0],
          }
      )
      assert_frame_equal(out, expected)
  
imports: from datetime import date, datetime, timedelta
  from typing import Any
  import numpy
  import pytest
  import polars
  from polars.testing import assert_frame_equal
label_desc: Use image node_id 16 for calling a global function with example usage: test_asof_join_nearest_by() without return types