code: def test_sample_expr() -> None:
      a = pl.Series("a", range(20))
      out = pl.select(
          pl.lit(a).sample(fraction=0.5, with_replacement=False, seed=1)
      ).to_series()
  
      assert out.shape == (10,)
      assert out.to_list() != out.sort().to_list()
      assert out.unique().shape == (10,)
      assert set(out).issubset(set(a))
  
      out = pl.select(
          pl.lit(a).sample(n=10, with_replacement=False, seed=1)
      ).to_series()
      assert out.shape == (10,)
      assert out.to_list() != out.sort().to_list()
      assert out.unique().shape == (10,)
  
      # pl.set_random_seed should lead to reproducible results.
      pl.set_random_seed(1)
      result1 = pl.select(pl.lit(a).sample(n=10)).to_series()
      pl.set_random_seed(1)
      result2 = pl.select(pl.lit(a).sample(n=10)).to_series()
      assert_series_equal(result1, result2)
  
file_path: polars/py-polars/tests/unit/operations/test_random.py
imports: from __future__ import annotations
  import pytest
  import polars
  from polars.testing import assert_frame_equal, assert_series_equal
label_desc: Use image node_id 2 for calling a global function with example usage: test_sample_expr() without return types