Skip to content

BUG: concat series with NA in multiindex fail to combine rows of same index #36499

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

Closed
2 of 3 tasks
hdou opened this issue Sep 20, 2020 · 3 comments
Closed
2 of 3 tasks
Labels
Duplicate Report Duplicate issue or pull request

Comments

@hdou
Copy link

hdou commented Sep 20, 2020

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import pandas as pd

names=['A1','A2']

idx1 = pd.MultiIndex.from_tuples([(1,1), (2, pd.NA)], names=names)
idx2 = pd.MultiIndex.from_tuples([(2, pd.NA), (3,3)], names=names)

s1 = pd.Series([11,12], index=idx1)
s2 = pd.Series([13,14], index=idx2)
s3 = pd.concat([s1, s2], axis=1)
print (s3)
# s3 fails to combine the two rows with index (2, NaN)
#            0     1
# A1 A2
# 1  1.0  11.0   NaN
# 2  NaN  12.0  13.0
#    NaN  12.0  13.0
# 3  3.0   NaN  14.0


# Workaround is to use merge after reset index
s1 = s1.reset_index()
s2 = s2.reset_index()
s3 = pd.merge(s1,s2,on=names,how='outer')
s3 = s3.set_index(names)
print (s3)
# Now the result is expected
# A1 A2
# 1  1.0  11.0   NaN
# 2  NaN  12.0  13.0
# 3  3.0   NaN  14.0

Problem description

[this should explain why the current behaviour is a problem and why the expected output is a better solution]

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]
INSTALLED VERSIONS

commit : 2a7d332
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Thu Jun 18 20:50:10 PDT 2020; root:xnu-4903.278.43~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.1.0
Cython : 0.29.21
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 : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@hdou hdou added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 20, 2020
@dsaxton
Copy link
Member

dsaxton commented Sep 20, 2020

See @phofl's response to your other issue #36479. Also #30750 #36060 #36470, etc.

@dsaxton dsaxton added Duplicate Report Duplicate issue or pull request and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 20, 2020
@kidrahahjo
Copy link

@hdou are you still having trouble with this?

@mroeschke
Copy link
Member

Thanks for the report. Agreed, this issue seems overlap/be address from the linked issues so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

4 participants