Skip to content

BUG: concat still sorts columns if they differ #43375

Closed
@mathrick

Description

@mathrick
  • I have checked that this issue has not already been reported.

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

>>> print(pd.concat([pd.DataFrame({i: i}, index=[i]) for i in range(10, 0, -1)], sort=False))
     1    2    3    4    5    6    7    8    9     10
10  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  10.0
9   NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  9.0   NaN
8   NaN  NaN  NaN  NaN  NaN  NaN  NaN  8.0  NaN   NaN
7   NaN  NaN  NaN  NaN  NaN  NaN  7.0  NaN  NaN   NaN
6   NaN  NaN  NaN  NaN  NaN  6.0  NaN  NaN  NaN   NaN
5   NaN  NaN  NaN  NaN  5.0  NaN  NaN  NaN  NaN   NaN
4   NaN  NaN  NaN  4.0  NaN  NaN  NaN  NaN  NaN   NaN
3   NaN  NaN  3.0  NaN  NaN  NaN  NaN  NaN  NaN   NaN
2   NaN  2.0  NaN  NaN  NaN  NaN  NaN  NaN  NaN   NaN
1   1.0  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN   NaN

Problem description

This was marked as fixed in #4588, but concat() still sorts the columns if they differ. The sort argument doesn't seem to have any effect on this.

Expected Output

      10   9    8    7    6    5    4    3    2    1 
10  10.0  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
9    NaN  9.0  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
8    NaN  NaN  8.0  NaN  NaN  NaN  NaN  NaN  NaN  NaN
7    NaN  NaN  NaN  7.0  NaN  NaN  NaN  NaN  NaN  NaN
6    NaN  NaN  NaN  NaN  6.0  NaN  NaN  NaN  NaN  NaN
5    NaN  NaN  NaN  NaN  NaN  5.0  NaN  NaN  NaN  NaN
4    NaN  NaN  NaN  NaN  NaN  NaN  4.0  NaN  NaN  NaN
3    NaN  NaN  NaN  NaN  NaN  NaN  NaN  3.0  NaN  NaN
2    NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  2.0  NaN
1    NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  1.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-77-generic
Version : #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 44.0.0
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
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

Labels

BugIndexRelated to the Index class or subclassesReshapingConcat, Merge/Join, Stack/Unstack, Explodesetopsunion, intersection, difference, symmetric_difference

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions