diff --git a/pandas/core/series.py b/pandas/core/series.py index 90d535e51580c..4a77a5669948a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -135,6 +135,12 @@ def __init__(self, data=None, index=None, dtype=None, name=None, if isinstance(data, MultiIndex): raise NotImplementedError + elif isinstance(data, Index): + # need to copy to avoid aliasing issues + if name is None: + name = data.name + data = data.values + copy = True elif isinstance(data, pa.Array): pass elif isinstance(data, Series): diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index bb46d563b904e..852d02764affc 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -2221,9 +2221,10 @@ def test_tolist(self): self.assertEqual(result, exp) def test_repr_with_unicode_data(self): - d = {"a": [u("\u05d0"), 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]} - index = pd.DataFrame(d).set_index(["a", "b"]).index - self.assertFalse("\\u" in repr(index)) # we don't want unicode-escaped + with pd.core.config.option_context("display.encoding",'UTF-8'): + d = {"a": [u("\u05d0"), 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]} + index = pd.DataFrame(d).set_index(["a", "b"]).index + self.assertFalse("\\u" in repr(index)) # we don't want unicode-escaped def test_unicode_string_with_unicode(self): d = {"a": [u("\u05d0"), 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}