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 2022/04/21 18:30:42 UTC

[GitHub] [spark] xinrong-databricks opened a new pull request, #36306: [SPARK-34827][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

xinrong-databricks opened a new pull request, #36306:
URL: https://github.com/apache/spark/pull/36306

   
   
   ### What changes were proposed in this pull request?
   Implement `ignore_index` of `DataFrame/Series.sample`
   
   
   ### Why are the changes needed?
   To increase pandas API coverage.
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes.
   
   
   ### How was this patch tested?
   Unit tests.
   


-- 
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 #36306: [SPARK-34827][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
itholic commented on code in PR #36306:
URL: https://github.com/apache/spark/pull/36306#discussion_r855727915


##########
python/pyspark/pandas/frame.py:
##########
@@ -8689,7 +8702,13 @@ def sample(
         sdf = self._internal.resolved_copy.spark_frame.sample(
             withReplacement=replace, fraction=frac, seed=random_state
         )
-        return DataFrame(self._internal.with_new_sdf(sdf))
+        if ignore_index:
+            spark_index_names = [
+                SPARK_INDEX_NAME_FORMAT(i) for i in range(self._internal.index_level)
+            ]
+            return DataFrame(sdf.drop(*spark_index_names))

Review Comment:
   ```suggestion
               return DataFrame(sdf.drop(*self._internal.index_spark_column_names))
   ```
   
   I think maybe `spark_index_names` is already in `self._internal.index_spark_column_names` ?



##########
python/pyspark/pandas/frame.py:
##########
@@ -8659,6 +8664,14 @@ def sample(
         falcon         2          2                 10
         fish           0          0                  8
 
+        A random 50% sample of the ``DataFrame``, while ignoring the index.
+
+        >>> df.sample(frac=0.5, random_state=1, ignore_index=True)  # doctest: +SKIP

Review Comment:
   qq: why do we skip this ?



-- 
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 closed pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`
URL: https://github.com/apache/spark/pull/36306


-- 
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] xinrong-databricks commented on a diff in pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on code in PR #36306:
URL: https://github.com/apache/spark/pull/36306#discussion_r856416943


##########
python/pyspark/pandas/frame.py:
##########
@@ -8689,7 +8702,13 @@ def sample(
         sdf = self._internal.resolved_copy.spark_frame.sample(
             withReplacement=replace, fraction=frac, seed=random_state
         )
-        return DataFrame(self._internal.with_new_sdf(sdf))
+        if ignore_index:
+            spark_index_names = [
+                SPARK_INDEX_NAME_FORMAT(i) for i in range(self._internal.index_level)
+            ]
+            return DataFrame(sdf.drop(*spark_index_names))

Review Comment:
   Good catch! Modified.



-- 
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] xinrong-databricks commented on a diff in pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on code in PR #36306:
URL: https://github.com/apache/spark/pull/36306#discussion_r856418197


##########
python/pyspark/pandas/frame.py:
##########
@@ -8659,6 +8664,14 @@ def sample(
         falcon         2          2                 10
         fish           0          0                  8
 
+        A random 50% sample of the ``DataFrame``, while ignoring the index.
+
+        >>> df.sample(frac=0.5, random_state=1, ignore_index=True)  # doctest: +SKIP

Review Comment:
   The sampled rows may not be fixed even with the seed, so we skip the doctests as well as the unit tests.



-- 
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 pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36306:
URL: https://github.com/apache/spark/pull/36306#issuecomment-1109215813

   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] xinrong-databricks commented on pull request #36306: [SPARK-34827][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on PR #36306:
URL: https://github.com/apache/spark/pull/36306#issuecomment-1105629070

   @ueshin @HyukjinKwon @itholic Thank you!


-- 
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 pull request #36306: [SPARK-34827][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
itholic commented on PR #36306:
URL: https://github.com/apache/spark/pull/36306#issuecomment-1105993698

   Maybe the JIRA number is incorrect ??
   
   Seems like it should be SPARK-38989.


-- 
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] xinrong-databricks commented on pull request #36306: [SPARK-38989][PYTHON] Implement `ignore_index` of `DataFrame/Series.sample`

Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on PR #36306:
URL: https://github.com/apache/spark/pull/36306#issuecomment-1106700588

   Thank you @itholic !


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