Skip to content

BUG: concat series returns error result when indexes use tuples with NA in them #36500

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 = [(1,1), (2, pd.NA)]
idx2 = [(2, pd.NA), (3,3)]

s1 = pd.Series([11,12], index=idx1)
s2 = pd.Series([13,14], index=idx2)
s3 = pd.concat([s1, s2], axis=1)
print (s3)
#           0     1
# 1 1    11.0   NaN
# 2 NaN   NaN   NaN     <= expect 12.0 13.0 as the values
# 3 3     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
@ivanovmg
Copy link
Member

ivanovmg commented Sep 21, 2020

Probably because pd.NA is not comparable (no equal, not not equal) with pd.NA?
I am not sure, but I guess index values have to be comparable with each other.

Similar cases (or maybe not).

This works.

df1 = pd.DataFrame({'a': [1, 2]}, index=[pd.NA, 1])
df2 = pd.DataFrame({'b': [4, 5]}, index=[1, pd.NA])
df = pd.concat([df1, df2], axis=1)
print(df)

producing

     a  b
NaN  1  5
1    2  4

This - does not.

df1 = pd.DataFrame({'a': [1, 2, 3]}, index=[pd.NA, 1, pd.NA])
df2 = pd.DataFrame({'b': [4, 5, 6]}, index=[1, pd.NA, pd.NA])
df = pd.concat([df1, df2], axis=1)
print(df)
Traceback (most recent call last):
  File "temp/formatters.py", line 29, in <module>
    df = pd.concat([df1, df2], axis=1)
  File "/workspaces/pandas/pandas/core/reshape/concat.py", line 288, in concat
    return op.get_result()
  File "/workspaces/pandas/pandas/core/reshape/concat.py", line 504, in get_result
    mgrs_indexers, self.new_axes, concat_axis=self.bm_axis, copy=self.copy
  File "/workspaces/pandas/pandas/core/internals/concat.py", line 85, in concatenate_block_managers
    return BlockManager(blocks, axes)
  File "/workspaces/pandas/pandas/core/internals/managers.py", line 142, in __init__
    self._verify_integrity()
  File "/workspaces/pandas/pandas/core/internals/managers.py", line 319, in _verify_integrity
    raise construction_error(tot_items, block.shape[1:], self.axes)
ValueError: Shape of passed values is (3, 2), indices imply (2, 2)

@mroeschke
Copy link
Member

Thanks for the report. Agreed that this seem to overlap/be related to linked issues so going to close in favor of those issues.

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