code: def test_error_when_df_contains_unseen_categories(
      df_enc, df_enc_rare
  ):
      # dataset to be transformed contains categories not present in
      # training dataset (unseen categories), unseen set to raise.
  
      msg = "During the encoding, NaN values were introduced in the feature(s) var_A."
  
      encoder = CountFrequencyEncoder(unseen="raise")
      encoder.fit(df_enc)
  
      # check for exception when unseen equals 'raise'
      with pytest.raises(ValueError) as record:
          encoder.transform(df_enc_rare)
  
      # check that the error message matches
      assert str(record.value) == msg
  
      # check for no error and no warning when unseen equals 'encode'
      with warnings.catch_warnings():
          warnings.simplefilter("error")
          encoder = CountFrequencyEncoder(unseen="encode")
          encoder.fit(df_enc)
          encoder.transform(df_enc_rare)
  
imports: import warnings
  import numpy
  import pandas
  import pytest
  from numpy import nan
  from feature_engine.encoding import CountFrequencyEncoder
label_desc: Use image node_id 5 for calling a global function with example usage: test_error_when_df_contains_unseen_categories(df_enc, df_enc_rare) without return types