Skip to content

BUG: Raise when casting infinity to int #28475

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

Merged
merged 4 commits into from
Sep 17, 2019
Merged

BUG: Raise when casting infinity to int #28475

merged 4 commits into from
Sep 17, 2019

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Sep 17, 2019

  • tests added / passed
  • passes black pandas
  • whatsnew entry

Raises a ValueError when attempting to cast a Float64Index with infinite values to a (non-ExtensionArray) integer dtype. Currently this returns a garbage value:

idx                                                               
# Float64Index([1.0, 2.0, inf], dtype='float64')
idx.astype(int)                                                   
# Int64Index([1, 2, -9223372036854775808], dtype='int64')

Related PR: #28438

@WillAyd WillAyd added the Error Reporting Incorrect or improved errors from pandas label Sep 17, 2019
@WillAyd WillAyd added this to the 1.0 milestone Sep 17, 2019
@WillAyd
Copy link
Member

WillAyd commented Sep 17, 2019

Haven't followed entire discussion but high level lgtm - thanks for the PR! I think @TomAugspurger can have ultimately say here though

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Need to agree that this is a bugfix and not an API change. I think we're safe calling it a bug.

# TODO(jreback); this can change once we have an EA Index type
# GH 13149
raise ValueError("Cannot convert NA to integer")
if self.hasnans:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this re-use astype_nansafe? That should handle things, including the nullable-integer check.

@jreback jreback merged commit 367670e into pandas-dev:master Sep 17, 2019
@jreback
Copy link
Contributor

jreback commented Sep 17, 2019

thanks @dsaxton

@dsaxton dsaxton deleted the inf-float branch September 19, 2019 13:40
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants