Skip to content

DOC: update the DataFrame.copy() docstring to current state with CoW #63289

@jorisvandenbossche

Description

@jorisvandenbossche

The current docstring has:

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 notes below).

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).

.. note::
    The ``deep=False`` behaviour as described above will change
    in pandas 3.0. `Copy-on-Write
    <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
    will be enabled by default, which means that the "shallow" copy
    is that is returned with ``deep=False`` will still avoid making
    an eager copy, but changes to the data of the original will *no*
    longer be reflected in the shallow copy (or vice versa). Instead,
    it makes use of a lazy (deferred) copy mechanism that will copy
    the data only when any changes to the original or shallow copy is
    made.

    You can already get the future behavior and improvements through
    enabling copy on write ``pd.options.mode.copy_on_write = True``

where the main explanation is still about the behaviour pre-3.0. The note already reflects the newer behaviour, but that should be updated from note to main explanation (and maybe we can keep a note mentioning that the behaviour in older versions is different, linking to the CoW docs)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions