Skip to content

Commit 9d3b4bb

Browse files
committed
BUG: Ensure that Index._data is an ndarray
Split from pandas-dev#23623, where it was causing issues with infer_dtype.
1 parent 2952e11 commit 9d3b4bb

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

pandas/core/indexes/base.py

-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,6 @@ def _simple_new(cls, values, name=None, dtype=None, **kwargs):
523523
**kwargs)._ndarray_values
524524

525525
if isinstance(values, (ABCSeries, cls)):
526-
# TODO: check this in all the callers. We shouldn't be getting
527-
# an Inex here.
528526
values = np.asarray(values._values)
529527

530528
assert isinstance(values, np.ndarray)

pandas/tests/indexes/test_base.py

+6
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@ def test_constructor_cast(self):
504504
with pytest.raises(ValueError, match=msg):
505505
Index(["a", "b", "c"], dtype=float)
506506

507+
def test_constructor_unwraps_index(self):
508+
a = pd.Index([True, False])
509+
b = pd.Index(a)
510+
expected = np.array([True, False], dtype=object)
511+
tm.assert_numpy_array_equal(b._data, expected)
512+
507513
def test_view_with_args(self):
508514

509515
restricted = ['unicodeIndex', 'strIndex', 'catIndex', 'boolIndex',

pandas/tests/indexes/test_numeric.py

+6
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,12 @@ def test_constructor_coercion_signed_to_unsigned(self, uint_dtype):
628628
with pytest.raises(OverflowError, match=msg):
629629
Index([-1], dtype=uint_dtype)
630630

631+
def test_constructor_unwraps_index(self):
632+
idx = pd.Index([1, 2])
633+
result = pd.Int64Index(idx)
634+
expected = np.array([1, 2], dtype='int64')
635+
tm.assert_numpy_array_equal(result._data, expected)
636+
631637
def test_coerce_list(self):
632638
# coerce things
633639
arr = Index([1, 2, 3, 4])

0 commit comments

Comments
 (0)