code: def test_gray_mapping(self):
      train_data = pd.DataFrame()
      train_data["cat_col"] = np.array([4, 9, 6, 7, 7, 9])
      train_data["other_col"] = range(train_data.shape[0])
      encoder = encoders.GrayEncoder(cols=["cat_col"])
      encoder.fit(train_data)
  
      expected_ordinal_mapping = {
          4.0: 1,
          9.0: 2,
          6.0: 3,
          7.0: 4,
          "nan": -2,
      }
      expected_mapping = pd.DataFrame(
          [
              [0, 0, 1],
              [0, 1, 1],
              [0, 1, 0],
              [1, 1, 0],
              [0, 0, 0],
              [0, 0, 0],
          ],
          columns=[f"cat_col_{i}" for i in range(3)],
          index=[1, 3, 4, 2, -1, -2],
      )
      self.assertEqual(len(encoder.mapping), 1)
      self.assertEqual(len(encoder.mapping[0].keys()), 2)
  
      actual_ordinal_encoding = encoder.ordinal_encoder.mapping[0][
          "mapping"
      ]
      actual_ordinal_encoding.index = (
          actual_ordinal_encoding.index.fillna("nan")
      )
      self.assertDictEqual(
          actual_ordinal_encoding.to_dict(), expected_ordinal_mapping
      )
      pd.testing.assert_frame_equal(
          encoder.mapping[0]["mapping"], expected_mapping
      )
  
      train_transformed = encoder.transform(train_data)
      train_data["cat_col"] = np.array([4, 9, 6, 7, 7, 9])
      expected_train_transformed = [
          [0, 0, 1, 0],
          [1, 1, 0, 1],
          [0, 1, 1, 2],
          [0, 1, 0, 3],
          [0, 1, 0, 4],
          [1, 1, 0, 5],
      ]
      expected_train_transformed = pd.DataFrame(
          expected_train_transformed,
          columns=[f"cat_col_{i}" for i in range(3)] + ["other_col"],
          index=train_data.index,
      )
      pd.testing.assert_frame_equal(
          train_transformed, expected_train_transformed
      )
      test_data = pd.DataFrame()
      test_data["cat_col"] = np.array([4, 3, None, np.nan])
      test_data["other_col"] = range(test_data.shape[0])
      expected_test_transformed = [
          [0, 0, 1, 0],
          [0, 0, 0, 1],
          [0, 0, 0, 2],
          [0, 0, 0, 3],
      ]
      expected_test_transformed = pd.DataFrame(
          expected_test_transformed,
          columns=[f"cat_col_{i}" for i in range(3)] + ["other_col"],
          index=test_data.index,
      )
      test_transformed = encoder.transform(test_data)
      pd.testing.assert_frame_equal(
          test_transformed, expected_test_transformed
      )
  
file_path: category_encoders/tests/test_gray.py
imports: import pandas
  from unittest import TestCase
  import numpy
  import category_encoders
label_desc: Use image node_id 2 for calling the TestGrayEncoder obj's underlying member method code with example usage: obj.test_gray_mapping() without return types