Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pandas/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def to_numeric(arg, errors="raise", downcast=None):

if downcast in ("integer", "signed"):
typecodes = np.typecodes["Integer"]
elif downcast == "unsigned" and np.min(values) >= 0:
elif downcast == "unsigned" and np.min(values, initial=0) >= 0:
typecodes = np.typecodes["UnsignedInteger"]
elif downcast == "float":
typecodes = np.typecodes["Float"]
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/tools/test_to_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,12 @@ def test_non_coerce_uint64_conflict(errors, exp):
else:
result = to_numeric(ser, errors=errors)
tm.assert_series_equal(result, ser)


@pytest.mark.parametrize("dc1", ["integer", "float", "unsigned"])
@pytest.mark.parametrize("dc2", ["integer", "float", "unsigned"])
def test_downcast_empty(dc1, dc2):

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that points to the original issue?

something like:

# https://github.com/pandas-dev/pandas/issues/32493

Should do it

assert np.array_equal(
pd.to_numeric([], downcast=dc1), pd.to_numeric([], downcast=dc2)
)