Skip to content

Commit 8d1be80

Browse files
authored
BUG: infer_objects with Intervals (#50090)
* BUG: infer_objects with Intervals * GH ref * fix ArrayManager case
1 parent 3af7170 commit 8d1be80

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ Strings
739739
Interval
740740
^^^^^^^^
741741
- Bug in :meth:`IntervalIndex.is_overlapping` incorrect output if interval has duplicate left boundaries (:issue:`49581`)
742+
- Bug in :meth:`Series.infer_objects` failing to infer :class:`IntervalDtype` for an object series of :class:`Interval` objects (:issue:`50090`)
742743
-
743744

744745
Indexing

pandas/core/internals/array_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ def _convert(arr):
384384
convert_datetime=True,
385385
convert_timedelta=True,
386386
convert_period=True,
387+
convert_interval=True,
387388
)
388389
if result is arr and copy:
389390
return arr.copy()

pandas/core/internals/blocks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,7 @@ def convert(
19801980
convert_datetime=True,
19811981
convert_timedelta=True,
19821982
convert_period=True,
1983+
convert_interval=True,
19831984
)
19841985
if copy and res_values is values:
19851986
res_values = values.copy()

pandas/tests/series/methods/test_infer_objects.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22

3+
from pandas import interval_range
34
import pandas._testing as tm
45

56

@@ -35,3 +36,11 @@ def test_infer_objects_series(self, index_or_series):
3536

3637
assert actual.dtype == "object"
3738
tm.assert_equal(actual, expected)
39+
40+
def test_infer_objects_interval(self, index_or_series):
41+
# GH#50090
42+
ii = interval_range(1, 10)
43+
obj = index_or_series(ii)
44+
45+
result = obj.astype(object).infer_objects()
46+
tm.assert_equal(result, obj)

0 commit comments

Comments
 (0)