-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame from_dict constructor ignores Ordered dict when orient='index' #8425
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
Comments
can you make your code runnable (so can simply copy/paste). you have some undefined variables. |
Sorry about that! Should be fine now. If not, will check when back in the office tomorrow. EDIT: the code now reproduces the above mentioned bug |
@Gimli510 that does look buggy. welcome a pull-request to fix. You can use your test example above, just step thru the code and see where its breaking and try a fix. |
@jreback I think I found where the bug comes from. # Up to this point, the future index is ordered as it should.
indexes = [['zShould be first', 'Should be second'], ['zShould be first', 'Should be second']]
# When indexes is a list with more than 1 items, we hit this path:
# return Index(lib.fast_unique_multiple_list(indexes))
# However,
lib.fast_unique_multiple_list(indexes) returns ['Should be second', 'zShould be first'] |
I think this should be handled in maybe add in a Then you can validate that if |
@jreback |
@jreback is this still an issue in the current version of df = pd.DataFrame.from_dict(ordered_dict_data, orient='index') sorts the index alphabetically. I've been using the following hack to address it: df = pd.DataFrame.from_dict(ordered_dict_data, orient='columns').T My hack, however, sorts the columns alphabetically. For the data that I have, it's easier for me to re-order these columns so the latter solution works better. To be precise, my data = OrderedDict(
'a': OrderedDict('aa': 5, 'bb': 10),
'b': OrderedDict('aa': 7, 'bb': 14),
...) If it's not fixed, I can take a stab at it. |
Still an open issue. |
This removes the deprecation warnings introduced in pandas-dev#18262, by reimplementing DataFrame.from_items() in the recommended way using DataFrame.from_dict() and collections.OrderedDict. This eliminates the maintenance burden of separate code for from_items(), while allowing existing uses to keep working. A small cleanup can be done once pandas-dev#8425 is fixed.
This removes the deprecation warnings introduced in pandas-dev#18262, by reimplementing DataFrame.from_items() in the recommended way using DataFrame.from_dict() and collections.OrderedDict. This eliminates the maintenance burden of separate code for from_items(), while allowing existing uses to keep working. A small cleanup can be done once pandas-dev#8425 is fixed.
This removes the deprecation warnings introduced in pandas-dev#18262, by reimplementing DataFrame.from_items() in the recommended way using DataFrame.from_dict() and collections.OrderedDict. This eliminates the maintenance burden of separate code for from_items(), while allowing existing uses to keep working. A small cleanup can be done once pandas-dev#8425 is fixed.
Hello,
I have been experimenting with OrderedDicts lately, and found a bug with the DataFrame from_dict constructor. Here is a sample code.
INSTALLED VERSIONS
commit: None
python: 3.3.5.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 26 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: fr_CH
pandas: 0.14.1
nose: 1.3.4
Cython: 0.20.1
numpy: 1.9.0
scipy: 0.13.3
statsmodels: 0.5.0
IPython: 2.2.0
sphinx: 1.2.3
patsy: 0.3.0
scikits.timeseries: None
dateutil: 2.2
pytz: 2013.9
bottleneck: None
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.0
openpyxl: None
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.5.7
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None
The text was updated successfully, but these errors were encountered: