Skip to content
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

BUG: Coerce to numeric despite uint64 conflict #17823

Merged
merged 1 commit into from
Oct 9, 2017

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Oct 9, 2017

Previously, to_numeric was not coercing elements to numeric if the conversion was going to be lossy (e.g. uint64 combined with nan), even when errors='coerce'. Now the errors parameter takes precedence.

Closes #17007.
Closes #17125.

@gfyoung gfyoung added Bug Numeric Operations Arithmetic, Comparison, and Logical operations labels Oct 9, 2017
@gfyoung gfyoung added this to the 0.21.0 milestone Oct 9, 2017
@gfyoung gfyoung force-pushed the to-numeric-coerce-float branch 2 times, most recently from 16bf62e to 0904a55 Compare October 9, 2017 05:59
@codecov
Copy link

codecov bot commented Oct 9, 2017

Codecov Report

Merging #17823 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17823      +/-   ##
==========================================
- Coverage   91.26%   91.24%   -0.02%     
==========================================
  Files         163      163              
  Lines       49980    49980              
==========================================
- Hits        45613    45604       -9     
- Misses       4367     4376       +9
Flag Coverage Δ
#multiple 89.04% <ø> (ø) ⬆️
#single 40.24% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.74% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f0ee53...0904a55. Read the comment docs.

@codecov
Copy link

codecov bot commented Oct 9, 2017

Codecov Report

Merging #17823 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17823      +/-   ##
==========================================
- Coverage   91.24%   91.22%   -0.02%     
==========================================
  Files         163      163              
  Lines       49992    49992              
==========================================
- Hits        45613    45604       -9     
- Misses       4379     4388       +9
Flag Coverage Δ
#multiple 89.02% <ø> (ø) ⬆️
#single 40.24% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.74% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ebe085...93e52e9. Read the comment docs.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Looks good! Some small comments on the tests.

(np.array([2**63, np.nan], dtype=object), set()),
(np.array([str(2**63), np.nan], dtype=object), set()),
(np.array([np.nan, 2**63], dtype=object), set()),
(np.array([np.nan, str(2**63)], dtype=object), set())])
Copy link
Member

Choose a reason for hiding this comment

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

is the na_values part of the parametrize needed since it is all the same empty set ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doh! Good catch. Will fix.

@@ -39,6 +39,11 @@
from pandas.util import testing as tm


@pytest.fixture(params=[True, False], ids=lambda val: str(val))
def coerce(request):
return request.param
Copy link
Member

Choose a reason for hiding this comment

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

Should we do this as a parameterize instead of fixture? (I don't know whether are some 'rules' where it is better to use one or the other, but in this case it really seems to be a parameterizing of the test, so I would find it easier to read the code if it uses paramatrize)

Copy link
Member Author

Choose a reason for hiding this comment

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

I use fixture whenever I find myself using the same parametrization multiple times. As you can see below, I use it three times.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

some comments / additional tests.

# see gh-17007 and gh-17125
#
# Still returns float despite the uint64-nan conflict,
# which would normally force the casting to object.
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 also test with errors='raise' and ignore here

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@gfyoung gfyoung force-pushed the to-numeric-coerce-float branch from 0904a55 to 93e52e9 Compare October 9, 2017 16:49
@gfyoung
Copy link
Member Author

gfyoung commented Oct 9, 2017

@jreback @jorisvandenbossche : All is green. PTAL.

return True

if self.null_:
msg = ("uint64 array detected, and such an "
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, so these cases were not actually tested then? (IOW you didn't have to fix any tests)?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm. I see you blew away the entire section and re-wrote.

@jreback jreback merged commit 3ba2cff into pandas-dev:master Oct 9, 2017
@jreback
Copy link
Contributor

jreback commented Oct 9, 2017

thanks!

@gfyoung gfyoung deleted the to-numeric-coerce-float branch October 10, 2017 03:20
ghost pushed a commit to reef-technologies/pandas that referenced this pull request Oct 16, 2017
alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants