Skip to content

Commit 25153d3

Browse files
committed
moar warnings
1 parent 59f41ff commit 25153d3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

doc/source/dsintro.rst

+18-3
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,24 @@ respects the order of the keyword arguments. You can use assign in the following
518518
519519
.. warning::
520520

521-
This may subtly change the behavior of your code when you are
522-
using :func:`DataFrame.assign` to update an existing column. Prior to Python 3.6,
523-
callables referring to other variables being updated would get the "old" values.
521+
Prior to Python 3.6, this may subtly change the behavior of your code when you are
522+
using :func:`DataFrame.assign` to update an existing column.
523+
524+
Since the function signature of ``assign`` is ``**kwargs``, a dictionary,
525+
the order of the new columns in the resulting DataFrame cannot be guaranteed
526+
to match the order you pass in. To make things predictable, items are inserted
527+
alphabetically (by key) at the end of the DataFrame.
528+
529+
.. ipython::
530+
:verbatim:
531+
532+
In [1]: # Don't do this, bad reference to `C`
533+
df.assign(C = lambda x: x['A'] + x['B'],
534+
D = lambda x: x['A'] + x['C'])
535+
In [2]: # Instead, break it into two assigns
536+
(df.assign(C = lambda x: x['A'] + x['B'])
537+
.assign(D = lambda x: x['A'] + x['C']))
538+
524539

525540
Indexing / Selection
526541
~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)