diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 263de57d32f31..e0a64897b3905 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -522,6 +522,10 @@ def _simple_new(cls, values, name=None, dtype=None, **kwargs): values = cls(values, name=name, dtype=dtype, **kwargs)._ndarray_values + if isinstance(values, (ABCSeries, cls)): + values = np.asarray(values._values) + + assert isinstance(values, np.ndarray) result = object.__new__(cls) result._data = values result.name = name diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 4a3efe22926f7..054efa00cd892 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -504,6 +504,12 @@ def test_constructor_cast(self): with pytest.raises(ValueError, match=msg): Index(["a", "b", "c"], dtype=float) + def test_constructor_unwraps_index(self): + a = pd.Index([True, False]) + b = pd.Index(a) + expected = np.array([True, False], dtype=object) + tm.assert_numpy_array_equal(b._data, expected) + def test_view_with_args(self): restricted = ['unicodeIndex', 'strIndex', 'catIndex', 'boolIndex', diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index c125db16bcbff..d1ad2308d19e5 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -628,6 +628,12 @@ def test_constructor_coercion_signed_to_unsigned(self, uint_dtype): with pytest.raises(OverflowError, match=msg): Index([-1], dtype=uint_dtype) + def test_constructor_unwraps_index(self): + idx = pd.Index([1, 2]) + result = pd.Int64Index(idx) + expected = np.array([1, 2], dtype='int64') + tm.assert_numpy_array_equal(result._data, expected) + def test_coerce_list(self): # coerce things arr = Index([1, 2, 3, 4])