modin.pandas.Series.copy¶

Series.copy(deep=True) → Self[source]¶

Make a copy of this object’s indices and data.

When deep=True (default), a new object will be created with a copy of the calling object’s data and indices. Modifications to the data or indices of the copy will not be reflected in the original object (see examples below). In Snowpark pandas API this will not copy the underlying table/data, but we create a logical copy of data and indices to provide same sematics as native pandas.

When deep=False, a new object will be created without copying the calling object’s data or index (only references to the data and index are copied). Any changes to the data of the original will be reflected in the shallow copy (and vice versa).

Parameters:

deep (bool, default True) – Make a deep copy, including a locial copy of the data and the indices. With deep=False neither the indices nor the data are copied.

Returns:

copy – Object type matches caller.

Return type:

Snowpark pandas Series or Snowpark pandas DataFrame

Examples

>>> s = pd.Series([1, 2], index=["a", "b"])
>>> s
a    1
b    2
dtype: int64
Copy
>>> s_copy = s.copy()
>>> s_copy
a    1
b    2
dtype: int64
Copy

Shallow copy versus default (deep) copy:

>>> s = pd.Series([1, 2], index=["a", "b"])
>>> deep = s.copy()
>>> shallow = s.copy(deep=False)
Copy

Updates to the data shared by shallow copy and original is reflected in both; deep copy remains unchanged.

>>> s.sort_values(ascending=False, inplace=True)
>>> shallow.sort_values(ascending=False, inplace=True)
>>> s
b    2
a    1
dtype: int64
>>> shallow
b    2
a    1
dtype: int64
>>> deep
a    1
b    2
dtype: int64
Copy