A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/49523 below:

should creating a Series from a Series return a shallow copy? (share data, not attributes) · Issue #49523 · pandas-dev/pandas · GitHub

Currently, if you create a Series from another Series, you get a new object, but because it shares the manager, it also shares the index:

>>> s = pd.Series([1, 2, 3])
>>> s2 = pd.Series(s)
>>> s2._mgr is s._mgr
True

# changing the index of one also updates the other
>>> s2.index = ["a", "b", "c"]
>>> s
a    1
b    2
c    3
dtype: int64

Is this the desired / expected behaviour?

When doing an explicit shallow copy, this doesn't happen:

>>> s = pd.Series([1, 2, 3])
>>> s2 = s.copy(deep=False)
>>> s2._mgr is s._mgr
False

>>> s2.index = ["a", "b", "c"]
>>> s
0    1
1    2
2    3
dtype: int64

In both cases, changing an element of either Series updates the other (eg s[0] = 10), which is currently expected with a Series(.., copy=False) / shallow copy. But so it is not about sharing values, but whether it should also share the underlying manager (with the result that changing attributes of that manager (the axes), also updates the other)

(running with current main, which is '2.0.0.dev0+566.g57d8d3a7cc')


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4