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() cannot concatenate more than 3 mixed-frequency dataframes with multi-index series #59775

Open
3 tasks done
sakaiando opened this issue Sep 11, 2024 · 2 comments
Assignees
Labels
Bug Needs Discussion Requires discussion from core team before further action Period Period data type Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@sakaiando
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

n = 5
p = 2
dfA = pd.DataFrame(np.random.rand(n,p),
                   columns=['A0','B0'],
                   index=pd.period_range(start='2000-1-1',periods=n,freq='Y'))

dfQ = pd.DataFrame(np.random.rand(n,p),
                   columns=['A0','B0'],
                   index=pd.period_range(start='2000-1-1',periods=n,freq='Q'))

dfM = pd.DataFrame(np.random.rand(n,p),
                   columns=['A0','B0'],
                   index=pd.period_range(start='2000-1-1',periods=n,freq='M'))

df1 = dfA.loc[:,['A0']].T.stack()
df2 = dfA.loc[:,['B0']].T.stack()
df3 = dfQ.loc[:,['A0']].T.stack()
df4 = dfQ.loc[:,['B0']].T.stack()
df5 = dfM.loc[:,['A0']].T.stack()
df6 = dfM.loc[:,['B0']].T.stack()

# these work
pd.concat([df1,df4])
pd.concat([df1,df2])
pd.concat([df1,df3])
pd.concat([df1,df2,df3])
pd.concat([dfA['A0'],dfQ['A0'],dfM['A0']])

# error
pd.concat([df1,df3,df2])
pd.concat([df1,df2,df3,df4])
pd.concat([df1,df3,df5])

Issue Description

pd.concat() can concatenate 3 multi-index dataframes when they have 2 frequencies, but cannot concatenate 4 dataframes.

Expected Behavior

pd.concat() should be able to concatenate a list of mixed-freq multiindex dataframes no matter how many items the list has.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.12.4.final.0
python-bits : 64
OS : Windows
OS-release : 2016Server
Version : 10.0.14393
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United States.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 72.1.0
pip : 24.0
Cython : 3.0.11
pytest : None
hypothesis : None
sphinx : 8.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.26.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.1
gcsfs : None
matplotlib : 3.9.1.post1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 17.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.0
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : 2.4.1
pyqt5 : None

@sakaiando sakaiando added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 11, 2024
@rhshadrach
Copy link
Member

Thanks for the report, agreed this looks inconsistent. I'm guessing we should raise rather than converting to object dtype. @jbrockmendel - any thoughts?

@rhshadrach rhshadrach added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Period Period data type Needs Discussion Requires discussion from core team before further action and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 14, 2024
@dberardi99
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Discussion Requires discussion from core team before further action Period Period data type Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants