Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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)


def test_downcast_empty():
Copy link
Member

Choose a reason for hiding this comment

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

Could you use pytest.mark.parametrize here?

dc_int = pd.to_numeric([], downcast="integer")
dc_float = pd.to_numeric([], downcast="float")
dc_us = pd.to_numeric([], downcast="unsigned")

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(dc_int, dc_float)
assert np.array_equal(dc_us, dc_float)