You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "itholic (via GitHub)" <gi...@apache.org> on 2023/09/04 02:26:00 UTC

[GitHub] [spark] itholic opened a new pull request, #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

itholic opened a new pull request, #42787:
URL: https://github.com/apache/spark/pull/42787

   ### What changes were proposed in this pull request?
   
   This PR proposes to fix the behavior of `MultiIndex.append` to do not checking names.
   
   ### Why are the changes needed?
   
   To match the behavior with pandas according to https://github.com/pandas-dev/pandas/pull/48288
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes, the behavior is changed to match with pandas:
   
   **Testing data**
   ```python
   >>> psmidx1
   MultiIndex([('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3)],
              names=['x', 'y', 'z'])
   >>> psmidx2
   MultiIndex([('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3)],
              names=['p', 'q', 'r'])
   ```
   
   **Before**
   ```python
   >>> psmidx1.append(psmidx2)
   MultiIndex([('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3),
               ('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3)],
              names=['x', 'y', 'z'])
   ```
   
   **After**
   ```python
   >>> psmidx1.append(psmidx2)
   MultiIndex([('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3),
               ('a', 'x', 1),
               ('b', 'y', 2),
               ('c', 'z', 3)],
              )
   ```
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Fix the existing UTs.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No.


-- 
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


[GitHub] [spark] itholic commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315309392


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   so I thought it was a bug in Pandas that is fixed in the Pandas 2.0.0.



-- 
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


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315315397


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   shouldn't we also mention this in our migration doc?



-- 
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


[GitHub] [spark] zhengruifeng commented on pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #42787:
URL: https://github.com/apache/spark/pull/42787#issuecomment-1705906007

   merged to master


-- 
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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315324075


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   ok, I misunderstood the Pandas PR. LTGM



-- 
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


[GitHub] [spark] itholic commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315309089


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   I believe it's an intentional behavior since they mentioned this in ["Bug fixes"](https://pandas.pydata.org/docs/dev/whatsnew/v2.0.0.html#bug-fixes) section in their release note?



-- 
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


[GitHub] [spark] zhengruifeng closed pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng closed pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality
URL: https://github.com/apache/spark/pull/42787


-- 
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


[GitHub] [spark] itholic commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315254128


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   We can simply set the `index_names` to `None` to follow the behavior of Pandas, since Pandas doesn't keep the name of `MultiIndex` when computing the `append` from Pandas 2.0.0. (See https://github.com/pandas-dev/pandas/pull/48288 more detail)
   
   cc @zhengruifeng @HyukjinKwon as CI passed.



-- 
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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315255478


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   is it a bug in Pandas that might be fixed in the future?



-- 
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


[GitHub] [spark] itholic commented on a diff in pull request #42787: [SPARK-43241][PS] `MultiIndex.append` not checking names for equality

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #42787:
URL: https://github.com/apache/spark/pull/42787#discussion_r1315337724


##########
python/pyspark/pandas/indexes/base.py:
##########
@@ -1917,18 +1917,12 @@ def append(self, other: "Index") -> "Index":
         sdf_other = other._internal.spark_frame.select(other._internal.index_spark_columns)
         sdf_appended = sdf_self.union(sdf_other)
 
-        # names should be kept when MultiIndex, but Index wouldn't keep its name.
-        if isinstance(self, MultiIndex):
-            index_names = self._internal.index_names
-        else:
-            index_names = None
-
         internal = InternalFrame(
             spark_frame=sdf_appended,
             index_spark_columns=[
                 scol_for(sdf_appended, col) for col in self._internal.index_spark_column_names
             ],
-            index_names=index_names,
+            index_names=None,

Review Comment:
   > shouldn't we also mention this in our migration doc?
   
   Hmm.. I didn't mention this as a behavior change since it's a bug fix, but on second thought maybe we'd better to mention in the migration guide anyway.
   
   Let me create a follow-up for updating the migration guide.



-- 
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