-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[BUG] add consistency to_numeric on empty list #32512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
to_numeric should work similarly on empty lists for downcast=unsigned/float/integer Addresses: GH32493
@@ -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(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick.
@pytest.mark.parametrize("dc1", ["integer", "float", "unsigned"]) | ||
@pytest.mark.parametrize("dc2", ["integer", "float", "unsigned"]) | ||
def test_downcast_empty(dc1, dc2): | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. can you add a whatsnew note in 1.1, bug fixes, numeric section. ping on green.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small change, pls merge master and ping on green.
pandas/core/tools/numeric.py
Outdated
@@ -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 (len(values) == 0 or np.min(values) >= 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use not len(values)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small change, pls merge master and ping on green.
@jreback Done 👍
to_numeric should work similarly on empty lists for downcast=unsigned/float/integer Addresses: GH32493
thanks @mikekutzma |
to_numeric should work similarly on empty lists for
downcast=unsigned/float/integer
Addresses: GH32493
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff