Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion python/pyspark/pandas/tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pandas as pd
import numpy as np

from pyspark.loose_version import LooseVersion
from pyspark import pandas as ps
from pyspark.pandas.exceptions import PandasNotImplementedError
from pyspark.pandas.namespace import _get_index_map, read_delta
Expand Down Expand Up @@ -579,7 +580,13 @@ def test_to_numeric(self):
# "coerce", "ignore" and "raise" with non-Series.
data = ["1", "2", None, "4", "hello"]
self.assert_eq(pd.to_numeric(data, errors="coerce"), ps.to_numeric(data, errors="coerce"))
self.assert_eq(pd.to_numeric(data, errors="ignore"), ps.to_numeric(data, errors="ignore"))
if LooseVersion(pd.__version__) < "3.0.0":
self.assert_eq(
pd.to_numeric(data, errors="ignore"), ps.to_numeric(data, errors="ignore")
)
else:
with self.assertRaisesRegex(ValueError, "invalid error value specified"):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the default value was raise, this looks okay to me.

BTW, do you think we need to re-fresh the doc, @ueshin ? The docs says ignore doesn't work for pandas-on-Spark Series args.

def to_numeric(arg, errors="raise"):
"""
Convert argument to a numeric type.
Parameters
----------
arg : scalar, list, tuple, 1-d array, or Series
Argument to be converted.
errors : {'raise', 'coerce'}, default 'raise'
* If 'coerce', then invalid parsing will be set as NaN.
* If 'raise', then invalid parsing will raise an exception.
* If 'ignore', then invalid parsing will return the input.
.. note:: 'ignore' doesn't work yet when `arg` is pandas-on-Spark Series.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, eventually we should update the docs, but so far pandas 3 is not fully supported and I'm still not sure whether we can make it by 4.2.0 release, so I think we should keep it as-is for now.

Also I see another PR to show warning with pandas 3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it~

ps.to_numeric(data, errors="ignore")

self.assertRaisesRegex(
ValueError,
Expand Down