From 004f0854690340745578812ef7f97f34fb99d2c0 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 6 Dec 2022 12:16:03 -0800 Subject: [PATCH 1/3] BUG: infer_objects with Intervals --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/internals/blocks.py | 1 + pandas/tests/series/methods/test_infer_objects.py | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index a4370a363bb57..d603d84c35251 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:`??`) - Indexing 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..fc9bd8d363e9e 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,10 @@ 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): + ii = interval_range(1, 10) + obj = index_or_series(ii) + + result = obj.astype(object).infer_objects() + tm.assert_equal(result, obj) From ab94a5e34fbb40099bb889079e9213a71b5cc2b5 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 6 Dec 2022 12:17:26 -0800 Subject: [PATCH 2/3] GH ref --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/tests/series/methods/test_infer_objects.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index d603d84c35251..45870245728ff 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -704,7 +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:`??`) +- 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/tests/series/methods/test_infer_objects.py b/pandas/tests/series/methods/test_infer_objects.py index fc9bd8d363e9e..9fc5cfa0810bf 100644 --- a/pandas/tests/series/methods/test_infer_objects.py +++ b/pandas/tests/series/methods/test_infer_objects.py @@ -25,6 +25,7 @@ def test_infer_objects_series(self, index_or_series): 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) From 196532d012f20eba1a4e2fe072c5e49c5f2ef7f2 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 6 Dec 2022 13:36:47 -0800 Subject: [PATCH 3/3] fix ArrayManager case --- pandas/core/internals/array_manager.py | 1 + 1 file changed, 1 insertion(+) 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()