Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ Other
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
- Bug in :func:`to_numeric` with :class:`ArrowDtype` raising ``ValueError`` when the array contained NA values. (:issue:`61641`)
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
- Bug in :meth:`DataFrame.apply` raising ``RecursionError`` when passing ``func=list[int]``. (:issue:`61565`)
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ def to_numeric(

values_dtype = getattr(values, "dtype", None)
if isinstance(values_dtype, ArrowDtype):
if is_numeric_dtype(values_dtype) and is_series:
return arg._constructor(values, index=arg.index, name=arg.name)

mask = values.isna()
values = values.dropna().to_numpy()

new_mask: np.ndarray | None = None
if is_numeric_dtype(values_dtype):
pass
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/tools/test_to_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,20 @@ def test_coerce_pyarrow_backend():
result = to_numeric(ser, errors="coerce", dtype_backend="pyarrow")
expected = Series([1, 2, None], dtype=ArrowDtype(pa.int64()))
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize(
"dtype",
[
"ArrowDtype",
],
)
def test_to_numeric_arrow_decimal_with_na(dtype):
Copy link
Member

Choose a reason for hiding this comment

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

In a comment in the original PR, there was a request to parametrize different dtypes that should be a no-op.

On the top of my head, I think it's possible to test Int64Dtype and Float64Dtype, although, I think it will require to create another test for non-pyarrow.

# GH 61641
pa = pytest.importorskip("pyarrow")
target_class = globals()[dtype]
Copy link
Member

Choose a reason for hiding this comment

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

This is very confusing. Can you parametrize with the class directly?

decimal_type = target_class(pa.decimal128(3, scale=2))
series = Series([1, None], dtype=decimal_type)
result = to_numeric(series, errors="coerce")

tm.assert_series_equal(result, series)
Loading