Repository: scikit-learn-contrib/category_encoders

Issue:
Error suggests input is numpy array when it's a dataframe with Categorical dtype
I'll try to make a proper mre later, but thought I'd drop this here for now:
https://stackoverflow.com/a/79486928/10495893

Hints from issue comments:
@PaulWestenthanner: Thanks for reporting this Ben, I'm on it, could reproduce it in their Colab

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8b3426b..034eb42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+v.2.8.1
+=======
+
+* Fix: Support and test string targets and `pd.Categorical` targets.
+* Fix: Docs typo.
+ 
 v.2.8.0
 =======
 
diff --git a/category_encoders/utils.py b/category_encoders/utils.py
index c5830e2..a9adca7 100644
--- a/category_encoders/utils.py
+++ b/category_encoders/utils.py
@@ -457,7 +457,7 @@ class BaseEncoder(BaseEstimator):
         if self.__sklearn_tags__().target_tags.required:
             if not is_numeric_dtype(y):
                 self.lab_encoder_ = LabelEncoder()
-                y = self.lab_encoder_.fit_transform(y)
+                y = pd.Series(self.lab_encoder_.fit_transform(y), index=y.index)
             else:
                 self.lab_encoder_ = None
 
@@ -621,7 +621,7 @@ class SupervisedTransformerMixin(sklearn.base.TransformerMixin):
         X, y = convert_inputs(X, y, deep=True)
         self._check_transform_inputs(X)
         if y is not None and self.lab_encoder_ is not None:
-            y = self.lab_encoder_.transform(y)
+            y = pd.Series(self.lab_encoder_.transform(y), index=y.index)
 
         if not list(self.cols):
             return X


Test patch:
diff --git a/tests/test_encoders.py b/tests/test_encoders.py
index b7131b5..3a08bb9 100644
--- a/tests/test_encoders.py
+++ b/tests/test_encoders.py
@@ -436,6 +436,36 @@ class TestEncoders(TestCase):
             encoder = getattr(encoders, encoder_name)()
             encoder.fit_transform(X, y)
 
+    def test_string_targets(self):
+        """Test encoders with targets of type pd.Categorical or string."""
+        X = pd.DataFrame({'feature': ['A', 'B', 'A', 'C']})
+        y_string = pd.Series(['yes', 'no', 'yes', 'no'])
+
+        for encoder_name in encoders.__all__:
+            with self.subTest(encoder_name=encoder_name):
+                enc = getattr(encoders, encoder_name)()
+
+                # Test with string target
+                enc.fit(X, y_string)
+                transformed = enc.transform(X)
+                th.verify_numeric(transformed)
+                self.assertEqual(len(transformed), 4)
+    def test_categorical_targets(self):
+        """Test encoders with targets of type pd.Categorical or string."""
+        X = pd.DataFrame({'feature': ['A', 'B', 'A', 'C']})
+        y_categorical = pd.Categorical([1, 0, 1, 0])
+
+        for encoder_name in encoders.__all__:
+            with self.subTest(encoder_name=encoder_name):
+                enc = getattr(encoders, encoder_name)()
+
+                # Test with pd.Categorical target
+                enc.fit(X, y_categorical)
+                transformed = enc.transform(X)
+                th.verify_numeric(transformed)
+                self.assertEqual(len(transformed), 4)
+
+
     def test_preserve_column_order(self):
         """Test that the encoder preserves the column order."""
         binary_cat_example = pd.DataFrame(