@@ -436,6 +436,36 @@ def test_types(self):
436436 encoder = getattr (encoders , encoder_name )()
437437 encoder .fit_transform (X , y )
438438
439+ def test_string_targets (self ):
440+ """Test encoders with targets of type pd.Categorical or string."""
441+ X = pd .DataFrame ({'feature' : ['A' , 'B' , 'A' , 'C' ]})
442+ y_string = pd .Series (['yes' , 'no' , 'yes' , 'no' ])
443+
444+ for encoder_name in encoders .__all__ :
445+ with self .subTest (encoder_name = encoder_name ):
446+ enc = getattr (encoders , encoder_name )()
447+
448+ # Test with string target
449+ enc .fit (X , y_string )
450+ transformed = enc .transform (X )
451+ th .verify_numeric (transformed )
452+ self .assertEqual (len (transformed ), 4 )
453+ def test_categorical_targets (self ):
454+ """Test encoders with targets of type pd.Categorical or string."""
455+ X = pd .DataFrame ({'feature' : ['A' , 'B' , 'A' , 'C' ]})
456+ y_categorical = pd .Categorical ([1 , 0 , 1 , 0 ])
457+
458+ for encoder_name in encoders .__all__ :
459+ with self .subTest (encoder_name = encoder_name ):
460+ enc = getattr (encoders , encoder_name )()
461+
462+ # Test with pd.Categorical target
463+ enc .fit (X , y_categorical )
464+ transformed = enc .transform (X )
465+ th .verify_numeric (transformed )
466+ self .assertEqual (len (transformed ), 4 )
467+
468+
439469 def test_preserve_column_order (self ):
440470 """Test that the encoder preserves the column order."""
441471 binary_cat_example = pd .DataFrame (
0 commit comments