Skip to content

Commit 3f22934

Browse files
committed
DOC: explain the mode.chained_assignment option
1 parent a764663 commit 3f22934

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

doc/source/indexing.rst

+13-6
Original file line numberDiff line numberDiff line change
@@ -1833,15 +1833,22 @@ 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.
1842-
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.
1841+
When using chained indexing, the order may determine whether a copy is returned
1842+
or not.
1843+
1844+
Pandas has the ``SettingWithCopyWarning`` because assigning to a copy of a
1845+
slice is frequently not intentional, but a mistake caused by chained indexing
1846+
returning a copy where a slice was expected. If you would like pandas to be
1847+
more or less trusting about assignment to a chained indexing expression, you
1848+
can set the :ref:`option <options>` ``mode.chained_assignment``, which can take
1849+
the values ``['raise', 'warn', None]``. ``'raise'`` will convert the warnings
1850+
to a ``SettingWithCopyException`` you have to deal with; ``warn``, the default,
1851+
raises a warning, and ``None`` will suppress the warnings entirely.
18451852

18461853
.. ipython:: python
18471854
:okwarning:

doc/source/options.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ io.hdf.dropna_table True drop ALL nan rows when appendin
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 'raise', 'warn', or None. Raise an
421+
exception, warn, or no action if
422+
trying to use :ref:`chained assignment <indexing.evaluation_order>`.
423423
mode.sim_interactive False Whether to simulate interactive mode
424424
for purposes of testing.
425425
mode.use_inf_as_na False True means treat None, NaN, -INF,

0 commit comments

Comments
 (0)