Repository: modin-project/modin
Issue category: Feature Request

Issue:
Update exception message for `insert` function



Hints:

Patch:
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
index 0f0856652bc..35e9d58d54f 100644
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -1048,10 +1048,17 @@ def insert(
             or isinstance(value, (array, np.ndarray))
             and len(value.shape) > 1
         ):
-            if value.shape[1] != 1:
+            if isinstance(value, (array, np.ndarray)) and value.shape[1] != 1:
                 raise ValueError(
                     f"Expected a 1D array, got an array with shape {value.shape}"
                 )
+            elif (
+                isinstance(value, (DataFrame, pandas.DataFrame)) and value.shape[1] != 1
+            ):
+                raise ValueError(
+                    "Expected a one-dimensional object, got a DataFrame with "
+                    + f"{len(value.columns)} columns instead."
+                )
             value = value.squeeze(axis=1)
         if not self._query_compiler.lazy_execution and len(self.index) == 0:
             if not hasattr(value, "index"):


Test patch:
diff --git a/modin/pandas/test/dataframe/test_map_metadata.py b/modin/pandas/test/dataframe/test_map_metadata.py
index 40e1a7aded6..c63a00bb38e 100644
--- a/modin/pandas/test/dataframe/test_map_metadata.py
+++ b/modin/pandas/test/dataframe/test_map_metadata.py
@@ -1344,7 +1344,15 @@ def test_insert(data):
     )
 
     # Bad inserts
-    eval_insert(modin_df, pandas_df, col="Bad Column", value=lambda df: df)
+    eval_insert(
+        modin_df,
+        pandas_df,
+        col="Bad Column",
+        value=lambda df: df,
+        raising_exceptions=ValueError(
+            f"Expected a one-dimensional object, got a DataFrame with {len(pandas_df.columns)} columns instead."
+        ),
+    )
     eval_insert(
         modin_df,
         pandas_df,
diff --git a/modin/pandas/test/utils.py b/modin/pandas/test/utils.py
index 258e4af6b7d..2a2ad8662aa 100644
--- a/modin/pandas/test/utils.py
+++ b/modin/pandas/test/utils.py
@@ -904,7 +904,7 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
                     assert not isinstance(
                         md_e, tuple(raising_exceptions)
                     ), f"not acceptable exception type: {md_e}"
-                elif raising_exceptions and type(raising_exceptions) is type:
+                elif raising_exceptions and type(raising_exceptions) is not type:
                     assert (
                         type(md_e) is type(raising_exceptions)
                         and md_e.args == raising_exceptions.args