-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Preserve index order when constructing DataFrame from dict #26113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81d9214
cb57553
b0e46eb
a972fb7
91b9a38
d419ee4
b54592f
0aed1ca
3201e19
bbbeec7
f9d82eb
adff27b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,8 @@ def _union_indexes(indexes, sort=True): | |
if len(indexes) == 1: | ||
result = indexes[0] | ||
if isinstance(result, list): | ||
result = Index(sorted(result)) | ||
result = sorted(result) if sort else result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this branch be removed altogether or does that break 35 compatibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it breaks python 3.5 compat. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just move the compat check from the construction module to here then? Would be simpler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be a little more complicated here since we would have to do another compat check in the |
||
result = Index(result) | ||
return result | ||
|
||
indexes, kind = _sanitize_and_check(indexes) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
from pandas._libs import lib | ||
from pandas._libs.tslibs import IncompatibleFrequency | ||
from pandas.compat import lmap, lrange, raise_with_traceback | ||
from pandas.compat import PY36, lmap, lrange, raise_with_traceback | ||
|
||
from pandas.core.dtypes.cast import ( | ||
construct_1d_arraylike_from_scalar, construct_1d_ndarray_preserving_na, | ||
|
@@ -301,7 +301,7 @@ def extract_index(data): | |
' an index') | ||
|
||
if have_series or have_dicts: | ||
index = _union_indexes(indexes) | ||
index = _union_indexes(indexes, sort=not PY36) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs a comment on why here |
||
|
||
if have_raw_arrays: | ||
lengths = list(set(raw_lengths)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls make clear of how this affects 3.5 and 3.6+
let's move this to the other api changes section as its not a bug rather an api change.