Skip to content

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

Closed
@moink

Description

@moink

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)

Metadata

Metadata

Assignees

Labels

Dtype ConversionsUnexpected or buggy dtype conversionsIntervalInterval data typeTestingpandas testing functions or related to the test suite

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions