code: def test_replace_callable_named_groups(any_string_dtype):
      # test regex named groups
      ser = Series(["Foo Bar Baz", np.nan], dtype=any_string_dtype)
      pat = r"(?P<first>\w+) (?P<middle>\w+) (?P<last>\w+)"
      repl = lambda m: m.group("middle").swapcase()
      with tm.maybe_produces_warning(
          PerformanceWarning, using_pyarrow(any_string_dtype)
      ):
          result = ser.str.replace(pat, repl, regex=True)
      expected = Series(["bAR", np.nan], dtype=any_string_dtype)
      tm.assert_series_equal(result, expected)
  
imports: from datetime import datetime
  import re
  import numpy
  import pytest
  from pandas.errors import PerformanceWarning
  import pandas.util._test_decorators
  import pandas
  from pandas import Series, _testing
  from pandas.tests.strings import _convert_na_value, object_pyarrow_numpy
label_desc: Use image node_id 19 for calling a global function with example usage: test_replace_callable_named_groups(any_string_dtype) without return types