Only sort dict columns in from_records for py < 3.6
State: closed

- [ ] closes #xxxx (no existing issue)
- [x] tests passed (no new test added - can add one if necessary)
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

DataFrame.from_records does not respect dictionary order on Python 3.6+. For example:

```
>>> df = pd.DataFrame.from_records({'C':[1], 'A':[2]})
>>> df
   A  C
0  2  1
```

This change respects dict ordering on Python 3.6+ in line with 0.23 pandas behaviour of constructor and from_dict:

```
>>> df = pd.DataFrame.from_records({'C':[1], 'A':[2]})
>>> df
   C  A
0  1  2
```

There appears to be further potential to reduce duplication if from_records called from_dict?


Labels:
name: DataFrame
description: DataFrame data structure

Comments:
Hello @llawall! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/core/frame.py`](https://github.com/llawall/pandas/blob/434910bcbd9c5c83736eaa13b2268ae03d71cb40/pandas/core/frame.py) !



##### Comment last updated on September 13, 2018 at 10:03 Hours UTC
Would at the very least need tests bundled with this, but can you also open an issue to discuss? The existing behavior is an explicit sort, not necessarily an undefined order for Python < 3.6 so it's not as if this is a bug being fixed but rather a behavioral change that could use discussion
Also, this would be somewhat unique as you have the potential for dicts of different orders in `records`. I believe in all our other changes to respect dict ordering, the data are columnar so you don't have this potential ambiguity.
@WillAyd : 
* I'll add a test for this - that is no problem. 
* With respect to "explicit sort", what makes this sort any different to the change to the change in [_init_dict](https://github.com/pandas-dev/pandas/pull/19884/files#diff-1e79abbbdd150d4771b91ea60a4e1cc7) used by constructor? Previously an OrderedDict was special cased but the columns were otherwise always sorted too. 

@TomAugspurger :
* I'm not quite sure I understand what you mean by "dicts of different orders in `records`"? 

I've opened #22708 for further discussion about this. Let's move the discussion there. 

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22687?src=pr&el=h1) Report
> Merging [#22687](https://codecov.io/gh/pandas-dev/pandas/pull/22687?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/c04035360a179e82fc534cb4f38979615c53191f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff           @@
##           master   #22687   +/-   ##
=======================================
  Coverage   92.17%   92.17%           
=======================================
  Files         169      169           
  Lines       50715    50715           
=======================================
  Hits        46747    46747           
  Misses       3968     3968
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.58% <100%> (ø)` | :arrow_up: |
| #single | `42.35% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22687?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/22687/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.19% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22687?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/22687?src=pr&el=footer). Last update [c040353...ddd8c7f](https://codecov.io/gh/pandas-dev/pandas/pull/22687?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Can you merge master here?
Sure. I’m away for a few days but will do it on my return. 
closing as stale. if you want to continue, pls ping.