Change tests of casting an interval range index from float to int to reflect current behaviour #38718
Labels
Dtype Conversions
Unexpected or buggy dtype conversions
Interval
Interval data type
Testing
pandas testing functions or related to the test suite
Milestone
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 raisingValueErrors
when casting an interval range index from float to int. My reading of #15832 is that it is unnecessary to raise aValueError
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 intest_subtype_integer_errors
but also add a test to ensure that casting an interval range from float to int works as expected.The text was updated successfully, but these errors were encountered: