ueshin commented on a change in pull request #34061:
URL: https://github.com/apache/spark/pull/34061#discussion_r713498668



##########
File path: python/pyspark/pandas/tests/test_ops_on_diff_frames.py
##########
@@ -503,6 +503,12 @@ def test_loc_getitem_boolean_series(self):
             (pdf1.A + 1).loc[pdf2.A > -3].sort_index(), (psdf1.A + 
1).loc[psdf2.A > -3].sort_index()
         )
 
+        pser = pd.Series([0, 1, 2, 3, 4], index=[20, 10, 30, 0, 50])
+        psser = ps.from_pandas(pser)
+        self.assert_eq(pser.loc[pdf2.A > -3].sort_index(), psser.loc[psdf2.A > 
-3].sort_index())
+        pser.name = psser.name = "B"
+        self.assert_eq(pser.loc[pdf2.A > -3].sort_index(), psser.loc[psdf2.A > 
-3].sort_index())

Review comment:
       Could you also try with Series on the same anchor?

##########
File path: python/pyspark/pandas/indexing.py
##########
@@ -439,7 +440,8 @@ def __getitem__(self, key: Any) -> Union["Series", 
"DataFrame"]:
                 temp_col = verify_temp_column_name(psdf, "__temp_col__")
 
                 psdf[temp_col] = key
-                return 
type(self)(psdf[self._psdf_or_psser.name])[psdf[temp_col]]
+                name = self._psdf_or_psser.name or DEFAULT_SERIES_NAME

Review comment:
       How about explicitly specify the column name instead of implicit name?
   
   ```py
   name = ???
   psdf = self._psdf_or_psser.to_frame(name)
   ```

##########
File path: python/pyspark/pandas/indexing.py
##########
@@ -439,7 +440,8 @@ def __getitem__(self, key: Any) -> Union["Series", 
"DataFrame"]:
                 temp_col = verify_temp_column_name(psdf, "__temp_col__")
 
                 psdf[temp_col] = key
-                return 
type(self)(psdf[self._psdf_or_psser.name])[psdf[temp_col]]
+                name = self._psdf_or_psser.name or DEFAULT_SERIES_NAME
+                return cast(Series, 
psdf[name][psdf[temp_col]]).rename(self._psdf_or_psser.name)

Review comment:
       This is not what the original one is expecting.
   
   ```py
   return type(self)(psdf[name])[psdf[temp_col]]
   ```




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