Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix stubname equal suffix in wide to long function #57868

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

tqa236
Copy link
Contributor

@tqa236 tqa236 commented Mar 16, 2024

As pandas allows an index in a multiindex and a column to have the same name, I think it's reasonable to allow stubname equal suffix.

However, I think the root cause is in the melt function. It's stated in the docstring that

    value_name : scalar, default 'value'
        Name to use for the 'value' column, can't be an existing column label.

But if value_name == var_name, illogical result is returned. Example:

df = pd.DataFrame(
    {
        "A": {0: "a", 1: "b", 2: "c"},
        "B": {0: 1, 1: 3, 2: 5},
        "C": {0: 2, 1: 4, 2: 6},
    }
)
pd.melt(
    df,
    id_vars=["A"],
    value_vars=["B"],
    var_name="myVarname",
    value_name="myVarname",
)

Result:

image

I think it's more reasonable to also raise an error if value_name == var_name in melt

@tqa236 tqa236 force-pushed the fix-wide-to-long branch from f17bd8e to ddad4a9 Compare March 19, 2024 20:04
@tqa236 tqa236 force-pushed the fix-wide-to-long branch from ddad4a9 to fe29c82 Compare April 4, 2024 12:34
@tqa236 tqa236 force-pushed the fix-wide-to-long branch from fe29c82 to 6c00603 Compare April 9, 2024 21:18
@tqa236
Copy link
Contributor Author

tqa236 commented Apr 9, 2024

Hi @mroeschke, can you take a look at this PR, please? It should be ready for review.

@mroeschke mroeschke added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Apr 23, 2024
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tqa236, and sorry for the delay. Not sure if two branches got mixed, seems like half of the changes here are unrelated to the topic of this PR.

doc/source/whatsnew/v3.0.0.rst Outdated Show resolved Hide resolved
pandas/core/indexes/accessors.py Outdated Show resolved Hide resolved
pandas/tests/series/indexing/test_datetime.py Outdated Show resolved Hide resolved
web/pandas/static/img/books/pandas_cookbook_3.jpeg Outdated Show resolved Hide resolved
@tqa236 tqa236 force-pushed the fix-wide-to-long branch from 5d0f39d to 3106d68 Compare May 23, 2025 05:41
@tqa236
Copy link
Contributor Author

tqa236 commented May 23, 2025

hi @datapythonista, thank you for the review. I also force pushed to the branch because I noticed that you also didn't make any comment on the actual content of the PR. Now this PR should be ready for review.

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

Successfully merging this pull request may close these issues.

BUG: pd.wide_to_long can't handle stubname equal to suffix
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.