# scikit-learn__scikit-learn-25747
# Loki Mode Multi-Agent Patch
# Attempts: 1

--- a/sklearn/utils/_set_output.py
+++ b/sklearn/utils/_set_output.py
@@ -55,7 +55,7 @@ def _wrap_in_pandas_container(
     if isinstance(data_to_wrap, pd.DataFrame):
         if columns is not None:
             data_to_wrap.columns = columns
-        if index is not None:
+        if index is not None and len(index) == len(data_to_wrap):
             data_to_wrap.index = index
         return data_to_wrap