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/09/01 05:07:10 UTC

[GitHub] [spark] itholic commented on a change in pull request #33882: [SPARK-36609][PYTHON] Add `errors` argument for `ps.to_numeric`.

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



##########
File path: python/pyspark/pandas/namespace.py
##########
@@ -2814,9 +2824,18 @@ def to_numeric(arg):
     1.0
     """
     if isinstance(arg, Series):
-        return arg._with_new_scol(arg.spark.column.cast("float"))
+        if errors == "coerce":
+            return arg._with_new_scol(arg.spark.column.cast("int"))

Review comment:
       I changed it to follow pandas' behavior below:
   
   ```python
   >>> pd.to_numeric(pd.Series(['1', '2', '3']))
   0    1
   1    2
   2    3
   dtype: int64
   
   >>> ps.to_numeric(ps.Series(['1', '2', '3']))
   0    1.0
   1    2.0
   2    3.0
   dtype: float32
   ```
   
   But I'll revert this change since we cannot handle the case below properly with this change.
   
   ```python
   >>> pd.to_numeric(pd.Series(['1.0', '2', '-3']))
   0    1.0
   1    2.0
   2   -3.0
   dtype: float64
   
   >>> ps.to_numeric(ps.Series(['1.0', '2', '-3']))
   0    1
   1    2
   2   -3
   dtype: int32
   ```




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