code: def test_replace_maintain_ordering():
      # GH51016
      dtype = pd.CategoricalDtype([0, 1, 2], ordered=True)
      ser = pd.Series([0, 1, 2], dtype=dtype)
      msg = (
          r"The behavior of Series\.replace \(and DataFrame.replace\) "
          "with CategoricalDtype"
      )
      with tm.assert_produces_warning(FutureWarning, match=msg):
          result = ser.replace(0, 2)
      expected_dtype = pd.CategoricalDtype([1, 2], ordered=True)
      expected = pd.Series([2, 1, 2], dtype=expected_dtype)
      tm.assert_series_equal(
          expected, result, check_category_order=True
      )
  
file_path: pandas/pandas/tests/arrays/categorical/test_replace.py
imports: import pytest
  import pandas
  from pandas import Categorical
  import pandas._testing
label_desc: Use image node_id 4 for calling a global function with example usage: test_replace_maintain_ordering() without return types