diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index a4370a363bb57..45870245728ff 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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 diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 918c70ff91da5..1780199a09de2 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -384,6 +384,7 @@ def _convert(arr): convert_datetime=True, convert_timedelta=True, convert_period=True, + convert_interval=True, ) else: return arr.copy() diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 95300c888eede..3dc55ac740226 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -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)] diff --git a/pandas/tests/series/methods/test_infer_objects.py b/pandas/tests/series/methods/test_infer_objects.py index 4710aaf54de31..9fc5cfa0810bf 100644 --- a/pandas/tests/series/methods/test_infer_objects.py +++ b/pandas/tests/series/methods/test_infer_objects.py @@ -1,5 +1,6 @@ import numpy as np +from pandas import interval_range import pandas._testing as tm @@ -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)