Skip to content

Commit 9629fef

Browse files
sietsejorisvandenbossche
authored andcommitted
DOC: explain the mode.chained_assignment option (pandas-dev#18635)
1 parent 24b8f1e commit 9629fef

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
@@ -1833,15 +1833,27 @@ that you've done this:
18331833
18341834
Yikes!
18351835

1836+
.. _indexing.evaluation_order:
1837+
18361838
Evaluation order matters
18371839
~~~~~~~~~~~~~~~~~~~~~~~~
18381840

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

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

18461858
.. ipython:: python
18471859
: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)