HyukjinKwon commented on a change in pull request #34957:
URL: https://github.com/apache/spark/pull/34957#discussion_r772205056



##########
File path: python/pyspark/pandas/frame.py
##########
@@ -3989,9 +3989,14 @@ def insert(
             )
 
         if is_name_like_tuple(column):
-            if len(column) != len(self.columns.levels):
-                # To be consistent with pandas
-                raise ValueError('"column" must have length equal to number of 
column levels.')
+            if isinstance(self.columns, pd.MultiIndex):

Review comment:
       > pandas API on Spark doesn't support assigning the tuple-like column 
name to the DataFrame as below:
   
   Seems like this is matched with the pandas behaviour. can we make it matched?
   
   ```python
   >>> import pandas as pd
   >>> pdf = pd.DataFrame({'a': [1,2,3]})
   >>> pdf
      a
   0  1
   1  2
   2  3
   >>> pdf.insert(0, ("a", "b"), [1,2,3])
   >>> pdf
      (a, b)  a
   0       1  1
   1       2  2
   2       3  3
   ```

##########
File path: python/pyspark/pandas/frame.py
##########
@@ -3989,9 +3989,14 @@ def insert(
             )
 
         if is_name_like_tuple(column):
-            if len(column) != len(self.columns.levels):
-                # To be consistent with pandas
-                raise ValueError('"column" must have length equal to number of 
column levels.')
+            if isinstance(self.columns, pd.MultiIndex):
+                if len(column) != len(self.columns.levels):
+                    # To be consistent with pandas
+                    raise ValueError('"column" must have length equal to 
number of column levels.')
+            else:
+                raise NotImplementedError(
+                    "Tuple-like name is not supported to non-MultiIndex column"

Review comment:
       What does this mean?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to