Skip to content

BUG: infer_objects with Intervals #50090

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 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ Strings
Interval
^^^^^^^^
- Bug in :meth:`IntervalIndex.is_overlapping` incorrect output if interval has duplicate left boundaries (:issue:`49581`)
- Bug in :meth:`Series.infer_objects` failing to infer :class:`IntervalDtype` for an object series of :class:`Interval` objects (:issue:`50090`)
-

Indexing
Expand Down
1 change: 1 addition & 0 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def _convert(arr):
convert_datetime=True,
convert_timedelta=True,
convert_period=True,
convert_interval=True,
)
else:
return arr.copy()
Expand Down
1 change: 1 addition & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,7 @@ def convert(
convert_datetime=True,
convert_timedelta=True,
convert_period=True,
convert_interval=True,
)
res_values = ensure_block_shape(res_values, self.ndim)
return [self.make_block(res_values)]
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/methods/test_infer_objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np

from pandas import interval_range
import pandas._testing as tm


Expand All @@ -22,3 +23,11 @@ def test_infer_objects_series(self, index_or_series):

assert actual.dtype == "object"
tm.assert_equal(actual, expected)

def test_infer_objects_interval(self, index_or_series):
# GH#50090
ii = interval_range(1, 10)
obj = index_or_series(ii)

result = obj.astype(object).infer_objects()
tm.assert_equal(result, obj)