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.wide_to_long can't handle stubname equal to suffix #46939

Open
2 of 3 tasks
YMRTN opened this issue May 4, 2022 · 3 comments · May be fixed by #57868
Open
2 of 3 tasks

BUG: pd.wide_to_long can't handle stubname equal to suffix #46939

YMRTN opened this issue May 4, 2022 · 3 comments · May be fixed by #57868
Assignees
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@YMRTN
Copy link

YMRTN commented May 4, 2022

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
import numpy as np
np.random.seed(123)
df = pd.DataFrame({"year1" : {0 : 4.5, 1 : 1.7, 2 : .8},
                   "year2" : {0 : 2.5, 1 : 1.2, 2 : .7},
                   "year3" : {0 : 2.6, 1 : 1.6, 2 : .6},
                   "year4" : {0 : 3.2, 1 : 1.3, 2 : .1},
                   "X"     : dict(zip(range(3), np.random.randn(3)))
                  })
df["id"] = df.index
pd.wide_to_long(df, stubnames="year", i="id", j="year")  # AttributeError: 'DataFrame' object has no attribute 'str'

Issue Description

pd.wide_to_long raises an AttributeError when the parameters stubnames and j (suffix) are equal. The AttributeError does not really tell you what's the problem.

Expected Behavior

I see two potential fixes:

  • Raise an AttributeError that tells you that stubnames and j can't be identical
  • Make it so that stubnames and j can be identical

Installed Versions

commit : 4bfe3d0
python : 3.9.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.4.2
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.1.2
setuptools : 57.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
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : 3.4.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@YMRTN YMRTN added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 4, 2022
@simonjayhawkins simonjayhawkins added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 4, 2022
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone May 4, 2022
@YMRTN
Copy link
Author

YMRTN commented May 4, 2022

I have a commit ready, but I'm unable to run the tests:
image

Any idea how I can resolve this?

@simonjayhawkins
Copy link
Member

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@tqa236 tqa236 linked a pull request Mar 16, 2024 that will close this issue
5 tasks
@tqa236
Copy link
Contributor

tqa236 commented Mar 19, 2024

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants