Skip to content

Commit 0c8ccdd

Browse files
sietseTomAugspurger
authored andcommitted
DOC: explain the mode.chained_assignment option (#18635)
1 parent 48c690a commit 0c8ccdd

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

doc/source/indexing.rst

+17-5
Original file line numberDiff line numberDiff line change
@@ -1835,15 +1835,27 @@ that you've done this:
18351835
18361836
Yikes!
18371837

1838+
.. _indexing.evaluation_order:
1839+
18381840
Evaluation order matters
18391841
~~~~~~~~~~~~~~~~~~~~~~~~
18401842

1841-
Furthermore, in chained expressions, the order may determine whether a copy is returned or not.
1842-
If an expression will set values on a copy of a slice, then a ``SettingWithCopy``
1843-
warning will be issued.
1843+
When you use chained indexing, the order and type of the indexing operation
1844+
partially determine whether the result is a slice into the original object, or
1845+
a copy of the slice.
1846+
1847+
Pandas has the ``SettingWithCopyWarning`` because assigning to a copy of a
1848+
slice is frequently not intentional, but a mistake caused by chained indexing
1849+
returning a copy where a slice was expected.
1850+
1851+
If you would like pandas to be more or less trusting about assignment to a
1852+
chained indexing expression, you can set the :ref:`option <options>`
1853+
``mode.chained_assignment`` to one of these values:
18441854

1845-
You can control the action of a chained assignment via the option ``mode.chained_assignment``,
1846-
which can take the values ``['raise','warn',None]``, where showing a warning is the default.
1855+
* ``'warn'``, the default, means a ``SettingWithCopyWarning`` is printed.
1856+
* ``'raise'`` means pandas will raise a ``SettingWithCopyException``
1857+
you have to deal with.
1858+
* ``None`` will suppress the warnings entirely.
18471859

18481860
.. ipython:: python
18491861
:okwarning:

doc/source/options.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,10 @@ io.hdf.dropna_table True drop ALL nan rows when appe
417417
io.parquet.engine None The engine to use as a default for
418418
parquet reading and writing. If None
419419
then try 'pyarrow' and 'fastparquet'
420-
mode.chained_assignment warn Raise an exception, warn, or no
421-
action if trying to use chained
422-
assignment, The default is warn
420+
mode.chained_assignment warn Controls ``SettingWithCopyWarning``:
421+
'raise', 'warn', or None. Raise an
422+
exception, warn, or no action if
423+
trying to use :ref:`chained assignment <indexing.evaluation_order>`.
423424
mode.sim_interactive False Whether to simulate interactive mode
424425
for purposes of testing.
425426
mode.use_inf_as_na False True means treat None, NaN, -INF,

0 commit comments

Comments
 (0)