|
82 | 82 | from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u,
|
83 | 83 | OrderedDict, raise_with_traceback)
|
84 | 84 | from pandas import compat
|
| 85 | +from pandas.compat import PY36 |
85 | 86 | from pandas.compat.numpy import function as nv
|
86 | 87 | from pandas.util._decorators import Appender, Substitution
|
87 | 88 | from pandas.util._validators import validate_bool_kwarg
|
@@ -2575,12 +2576,12 @@ def assign(self, **kwargs):
|
2575 | 2576 |
|
2576 | 2577 | Notes
|
2577 | 2578 | -----
|
2578 |
| - Since ``kwargs`` is a dictionary, the order of your |
2579 |
| - arguments may not be preserved if you are using Python 3.5 and earlier. |
2580 |
| - To make things predicatable, the columns are inserted in alphabetical |
2581 |
| - order, at the end of your DataFrame. Assigning multiple columns within |
2582 |
| - the same ``assign`` is possible, but you cannot reference other columns |
2583 |
| - created within the same ``assign`` call. |
| 2579 | + For python 3.6 and above, the columns are inserted in the order of |
| 2580 | + **kwargs. For python 3.5 and earlier, since **kwargs is unordered, |
| 2581 | + the columns are inserted in alphabetical order at the end of your |
| 2582 | + DataFrame. Assigning multiple columns within the same ``assign`` |
| 2583 | + is possible, but you cannot reference other columns created within |
| 2584 | + the same ``assign`` call. |
2584 | 2585 |
|
2585 | 2586 | Examples
|
2586 | 2587 | --------
|
@@ -2624,11 +2625,11 @@ def assign(self, **kwargs):
|
2624 | 2625 | for k, v in kwargs.items():
|
2625 | 2626 | results[k] = com._apply_if_callable(v, data)
|
2626 | 2627 |
|
2627 |
| - # sort by key for 3.5 and earlier, but preserve order for 3.6 and later |
2628 |
| - if sys.version_info <= (3, 5): |
2629 |
| - results = sorted(results.items()) |
2630 |
| - else: |
| 2628 | + # preserve order for 3.6 and later, but sort by key for 3.5 and earlier |
| 2629 | + if PY36: |
2631 | 2630 | results = results.items()
|
| 2631 | + else: |
| 2632 | + results = sorted(results.items()) |
2632 | 2633 | # ... and then assign
|
2633 | 2634 | for k, v in results:
|
2634 | 2635 | data[k] = v
|
|
0 commit comments