Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

df1 = pd.DataFrame.from_dict({'a': ['A1', 'A2'], 'b': 'B'}, orient='index')
df2 = pd.DataFrame.from_dict({'b': 'B', 'a': ['A1', 'A2']}, orient='index')

Issue Description

df1 has columns [0, 1] with the array exploded df2 has only one column(0) with the array as value

Expected Behavior

Expected the order of the items of the dictionary to not impact on the result of the data frame. Since it's possible to pass a combination of scalars and lists, I would expect it to work the same regardless the dict items order.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 8dab54d6573f7186ff0c3b6364d5e4dd635ff3e7 python : 3.11.0.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-56-generic Version : #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.5.2 numpy : 1.24.1 pytz : 2022.7 dateutil : 2.8.2 setuptools : 65.6.3 pip : 22.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None

Comment From: dicristina

Make the values of your dictionaries array-like:

df1 = pd.DataFrame.from_dict({'a': ['A1', 'A2'], 'b': ['B']}, orient='index')
df2 = pd.DataFrame.from_dict({'b': ['B'], 'a': ['A1', 'A2']}, orient='index')

The documentation states that pd.DataFrame.from_dict is to be used to "Construct DataFrame from dict of array-like or dicts". A string is not considered array-like in this case.

Comment From: topper-123

I agree those two operation should give the same rows, so this is a bug.

More generally, we normally treat listlikes in DataFrame/series constructors and I think we should to that here too, though that may be an enhancement, so goes beyond this concrete issue. Also I'd expect a scalar to explode rowwise , so I'd actually expect df1 to be:

    0   1
a  A1  A2
b   B   B

But that's also en enhancement,maybe.