preserve kwargs order on assign func for py36plus - #14207
State: closed

- [x] closes #14207
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: API Design

Comments:
This should apply to py36+, and we don't want to have to update this with
every python release. We *could* add a `PY_LT_36` in pandas.compat`, but
that seems like overkill for now.

On Fri, Sep 22, 2017 at 4:34 PM, Jeff Reback <notifications@github.com>
wrote:

> *@jreback* requested changes on this pull request.
> ------------------------------
>
> In pandas/core/frame.py
> <https://github.com/pandas-dev/pandas/pull/17632#discussion_r140601578>:
>
> >          for k, v in kwargs.items():
>              results[k] = com._apply_if_callable(v, data)
>
> +        # sort by key for 3.5 and earlier, but preserve order for 3.6 and later
> +        if sys.version_info <= (3, 5):
>
> use pandas.compat.PY36 here
> ------------------------------
>
> In pandas/tests/frame/test_mutate_columns.py
> <https://github.com/pandas-dev/pandas/pull/17632#discussion_r140601635>:
>
> >          # GH 9818
>          df = DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
>          result = df.assign(D=df.A + df.B, C=df.A - df.B)
> -        expected = DataFrame([[1, 2, -1, 3], [3, 4, -1, 7]],
> -                             columns=list('ABCD'))
> +
> +        if sys.version_info <= (3, 5):
>
> see above
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/17632#pullrequestreview-64704936>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIrOW9xVe9H__nxlGLxzPCbXEt8VJks5slCf7gaJpZM4PhNZw>
> .
>

> This should apply to py36+, and we don't want to have to update this with
every python release. We *could* add a `PY_LT_36` in pandas.compat`, but
that seems like overkill for now.

we already have this which is ``PY36`` means >= 3.6, or you can do ``not PY35`` which is < 3.6.
Ah, I thought those were exact. Yep let's do that then.

Thanks for the feedback, gents.  I'll get these fixed
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=h1) Report
> Merging [#17632](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/4004367fb815645bb7f5bbb518eee62cbd476e3a?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `83.33%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17632/graphs/tree.svg?src=pr&width=650&token=eZ4WkYLtcO&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17632      +/-   ##
==========================================
- Coverage   91.22%    91.2%   -0.02%     
==========================================
  Files         163      163              
  Lines       49655    49659       +4     
==========================================
- Hits        45297    45291       -6     
- Misses       4358     4368      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <83.33%> (-0.01%)` | :arrow_down: |
| #single | `40.18% <83.33%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <83.33%> (-0.15%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=footer). Last update [4004367...eff8af7](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=h1) Report
> Merging [#17632](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/4004367fb815645bb7f5bbb518eee62cbd476e3a?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `83.33%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17632/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&width=650&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17632      +/-   ##
==========================================
- Coverage   91.22%    91.2%   -0.02%     
==========================================
  Files         163      163              
  Lines       49655    49659       +4     
==========================================
- Hits        45297    45291       -6     
- Misses       4358     4368      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <83.33%> (-0.01%)` | :arrow_down: |
| #single | `40.18% <83.33%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <83.33%> (-0.15%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=footer). Last update [4004367...eff8af7](https://codecov.io/gh/pandas-dev/pandas/pull/17632?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @bobhaffner 
It's the least I could do, @jreback.  Thanks to you and @TomAugspurger for the guidance and everything else you do for the project