Skip to content
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

BUG: pd.concat ignores axis="columns" argument #48856

Closed
2 of 3 tasks
CarlaFernandez opened this issue Sep 29, 2022 · 1 comment
Closed
2 of 3 tasks

BUG: pd.concat ignores axis="columns" argument #48856

CarlaFernandez opened this issue Sep 29, 2022 · 1 comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@CarlaFernandez
Copy link

Pandas version checks

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

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

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

Reproducible Example

import pandas as pd
df1 = pd.read_json('{"PassengerId":{"1":2.0},"Survived":{"1":1.0},"Pclass":{"1":1.0},"Name":{"1":"Cumings, Mrs. John Bradley (Florence Briggs Thayer)"},"Sex":{"1":"female"},"Age":{"1":38.0},"SibSp":{"1":1.0},"Parch":{"1":0.0},"Ticket":{"1":"PC 17599"},"Fare":{"1":71.2833},"Cabin":{"1":"C85"},"Embarked":{"1":"C"},"score":{"1":1.0}}')
df2 = pd.read_json('{"score_calib":{"0":0.9647065937}}')
pd.concat((df1, df2), axis="columns")

Issue Description

The result from the reproducible example is the following:
image

This seems to be due to the differences in the indices (df1 has index 1 and df2 has index 0), however I think pd.concat should either:

  1. Ignore this and concat the dataframes as-is, raising a warning and creating a new index for the resulting dataframe.
  2. Raise an exception that the indexes are different and break.

Because of the nature and usage of pd.concat(axis="columns"), I think alternative 1 would be preferable.

Expected Behavior

The expected behaviour is to obtain a dataframe with a single row and 14 columns like this one:
image

Installed Versions

On a Databricks instance:

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1090-azure
Version : #95~18.04.1-Ubuntu SMP Sun Aug 14 20:09:27 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.22.4
pytz : 2020.5
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0
Cython : 0.29.23
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.2
fsspec : 0.9.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : 0.55.2

Also happening in a Windows environment:

INSTALLED VERSIONS

commit : e8093ba
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 11, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : es_ES.cp1252
pandas : 1.4.3
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 60.2.0
pip : 21.3.1
Cython : None
pytest : 7.1.2
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
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.0
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@CarlaFernandez CarlaFernandez added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 29, 2022
@CarlaFernandez
Copy link
Author

Closing the issue, just realized this is what the argument ignore_index=True is for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant