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

Change tests of casting an interval range index from float to int to reflect current behaviour #38718

Closed
moink opened this issue Dec 27, 2020 · 2 comments · Fixed by #38719
Closed
Assignees
Labels
Dtype Conversions Unexpected or buggy dtype conversions Interval Interval data type Testing pandas testing functions or related to the test suite
Milestone

Comments

@moink
Copy link
Member

moink commented Dec 27, 2020

This is to address an issue I came across in PR #38697 where there is a test, test_subtype_integer_errors, in pandas/tests/indexes/interval/test_astype.py marked as failing because it is not raising ValueErrors when casting an interval range index from float to int. My reading of #15832 is that it is unnecessary to raise a ValueError in this case.

As I wrote in the comments to #38697:

The question is, as a user of pandas, if you had an interval range such as [(0.0, 0.25], (0.25, 0.5], (0.5, 0.75], (0.75, 1.0], (1.0, 1.25], (1.25, 1.5], (1.5, 1.75], (1.75, 2.0], (2.0, 2.25], (2.25, 2.5]], and you cast it to int, what would you want or expect? The old (failing) version of the test said you expect a ValueError. I am saying you expect [(0, 0], (0, 0], (0, 0], (0, 1], (1, 1], (1, 1], (1, 1], (1, 2], (2, 2], (2, 2]] which, as I said, looks not that useful as an IntervalIndex, but is not wrong either.

So what I plan to do is delete two pytest.raises calls in test_subtype_integer_errors but also add a test to ensure that casting an interval range from float to int works as expected.

Your logic makes sense to me, but I'd defer to someone with more experience on how we handle IntervalIndex.

If being removed from this test, we definitely want to make sure this specific casting behavior is being tested somewhere. To keep this pr simple and easier to merge, I'd suggest reverting modification of this test, then making a followup pr to clean up this test and add tests for any untested casting behavior.

Originally posted by @mzeitlin11 in #38697 (comment)

@moink
Copy link
Member Author

moink commented Dec 27, 2020

take

@mzeitlin11 mzeitlin11 added Dtype Conversions Unexpected or buggy dtype conversions Interval Interval data type Testing pandas testing functions or related to the test suite labels Dec 27, 2020
@jreback jreback added this to the 1.3 milestone Dec 27, 2020
@jreback
Copy link
Contributor

jreback commented Dec 27, 2020

this is what numpy does when casting floats -> ints, so its correct, though agreed not as useful as one would like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Interval Interval data type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants