code: def test_asof_join_nearest_by_with_tolerance() -> None:
      df1 = pl.DataFrame(
          {
              "group": [
                  1,
                  1,
                  1,
                  1,
                  1,
                  2,
                  2,
                  2,
                  2,
                  2,
                  3,
                  3,
                  3,
                  3,
                  3,
                  4,
                  4,
                  4,
                  4,
                  4,
                  5,
                  5,
                  5,
                  5,
                  5,
                  6,
                  6,
                  6,
                  6,
                  6,
              ],
              "asof_key": pl.Series(
                  [
                      1,
                      2,
                      3,
                      4,
                      5,
                      7,
                      8,
                      9,
                      10,
                      11,
                      1,
                      2,
                      3,
                      4,
                      5,
                      1,
                      2,
                      3,
                      4,
                      5,
                      1,
                      2,
                      3,
                      4,
                      5,
                      1,
                      2,
                      3,
                      4,
                      5,
                  ],
                  dtype=pl.Float32,
              ),
              "a": [
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
              ],
          }
      )
  
      df2 = pl.DataFrame(
          {
              "group": [
                  1,
                  1,
                  1,
                  1,
                  1,
                  2,
                  2,
                  2,
                  2,
                  2,
                  3,
                  3,
                  3,
                  3,
                  3,
                  4,
                  4,
                  4,
                  4,
                  4,
                  5,
                  5,
                  5,
                  5,
                  5,
                  6,
                  6,
                  6,
                  6,
                  6,
              ],
              "asof_key": pl.Series(
                  [
                      7,
                      8,
                      9,
                      10,
                      11,
                      1,
                      2,
                      3,
                      4,
                      5,
                      6,
                      7,
                      8,
                      9,
                      10,
                      5,
                      -3,
                      -2,
                      -1,
                      0,
                      0,
                      2,
                      2.4,
                      3.4,
                      10,
                      -3,
                      3,
                      8,
                      9,
                      10,
                  ],
                  dtype=pl.Float32,
              ),
              "b": [
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
                  1,
                  2,
                  3,
                  4,
                  5,
              ],
          }
      )
  
      expected = df1.with_columns(
          pl.Series(
              [
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  None,
                  1,
                  5,
                  None,
                  None,
                  1,
                  1,
                  2,
                  2,
                  4,
                  4,
                  None,
                  None,
                  2,
                  2,
                  2,
                  None,
              ]
          ).alias("b")
      )
      df1 = df1.sort(by=["group", "asof_key"])
      df2 = df2.sort(by=["group", "asof_key"])
      expected = expected.sort(by=["group", "a"])
  
      out = df1.join_asof(
          df2,
          by="group",
          on="asof_key",
          strategy="nearest",
          tolerance=1.0,
      ).sort(by=["group", "a"])
      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",
          tolerance=0.5,
      )
      expected = pl.DataFrame(
          {
              "a": [1, 1, 1],
              "asof_key_left": [10.00001, 20.0, 30.0],
              "asof_key_right": [10.00001, 20.0001, None],
          }
      )
      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 17 for calling a global function with example usage: test_asof_join_nearest_by_with_tolerance() without return types