You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/12/21 04:25:08 UTC

[GitHub] [spark] itholic commented on a change in pull request #34957: [SPARK-37668][PYTHON] 'Index' object has no attribute 'levels' in pyspark.pandas.frame.DataFrame.insert

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



##########
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:
       I meant tuple-like name (e.g. `("a", "b")`) is not supported for DataFrame with `Index` unlike pandas.
   
   **pandas**
   ```python
   >>> pdf[("a", "b")] = [4, 5, 6]
   >>> pdf
      a  (a, b)
   0  1       4
   1  2       5
   2  3       6
   ```
   
   **pandas API on Spark**
   ```python
   >>> psdf[("a", "b")] = [4, 5, 6]
   Traceback (most recent call last):
   ...
   KeyError: 'Key length (2) exceeds index depth (1)'
   ```




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org