code: def test_apply_replace_columns(df):
      def add_sorted_cumsum(df):
          x = df["x"].sort_values()
          z = df.loc[x.index, "y"].cumsum()
          return pd.DataFrame(dict(x=x.values, z=z.values))
  
      res = GroupBy(["a"]).apply(df, add_sorted_cumsum)
      assert_array_equal(res.index, df.index)
      assert_array_equal(res.columns, ["a", "x", "z"])
      assert_array_equal(res["a"], ["a", "a", "a", "b", "b"])
      assert_array_equal(res["x"], [1, 1, 2, 2, 3])
      assert_array_equal(res["z"], [0.2, 0.5, 1.3, 0.4, 0.9])
  
file_path: seaborn/tests/_core/test_groupby.py
imports: import numpy
  import pandas
  import pytest
  from numpy.testing import assert_array_equal
  from seaborn._core.groupby import GroupBy
label_desc: Use image node_id 12 for calling a global function with example usage: test_apply_replace_columns(df) and returns: pd