code: def test_encode_top_categories():
      # test case 3: encode only the most popular categories
  
      df = pd.DataFrame(
          {
              "var_A": ["A"] * 5
              + ["B"] * 11
              + ["C"] * 4
              + ["D"] * 9
              + ["E"] * 2
              + ["F"] * 2
              + ["G"] * 7,
              "var_B": ["A"] * 11
              + ["B"] * 7
              + ["C"] * 4
              + ["D"] * 9
              + ["E"] * 2
              + ["F"] * 2
              + ["G"] * 5,
              "var_C": ["A"] * 4
              + ["B"] * 5
              + ["C"] * 11
              + ["D"] * 9
              + ["E"] * 2
              + ["F"] * 2
              + ["G"] * 7,
          }
      )
  
      encoder = OneHotEncoder(
          top_categories=4, variables=None, drop_last=False
      )
      X = encoder.fit_transform(df)
  
      # test init params
      assert encoder.top_categories == 4
      # test fit attr
      transf = {
          "var_A_D": 9,
          "var_A_B": 11,
          "var_A_A": 5,
          "var_A_G": 7,
          "var_B_A": 11,
          "var_B_D": 9,
          "var_B_G": 5,
          "var_B_B": 7,
          "var_C_D": 9,
          "var_C_C": 11,
          "var_C_G": 7,
          "var_C_B": 5,
      }
  
      # test fit attr
      assert encoder.variables_ == ["var_A", "var_B", "var_C"]
      assert encoder.variables_binary_ == []
      assert encoder.n_features_in_ == 3
      assert encoder.encoder_dict_ == {
          "var_A": ["B", "D", "G", "A"],
          "var_B": ["A", "D", "B", "G"],
          "var_C": ["C", "D", "G", "B"],
      }
      # test transform output
      for col in transf.keys():
          assert X[col].sum() == transf[col]
      assert "var_B" not in X.columns
      assert "var_B_F" not in X.columns
  
file_path: feature_engine/tests/test_encoding/test_onehot_encoder.py
imports: import pandas
  import pytest
  from sklearn.pipeline import Pipeline
  from feature_engine.encoding import OneHotEncoder
label_desc: Use image node_id 3 for calling a global function with example usage: test_encode_top_categories() without return types