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

feat!: Update resulting column names in pivot when pivoting by multiple values #16439

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented May 23, 2024

Closes #14491

Changes

  • In DataFrame.pivot, when specifying multiple values columns, the result would redundantly include the column column in the column names. This has been addressed.

Example

Before:

>>> df = pl.DataFrame(
...     {
...         "name": ["Cady", "Cady", "Karen", "Karen"],
...         "subject": ["maths", "physics", "maths", "physics"],
...         "test_1": [98, 99, 61, 58],
...         "test_2": [100, 100, 60, 60],
...     }
... )
>>> df.pivot(index='name', columns='subject', values=['test_1', 'test_2'])
shape: (2, 5)
┌───────┬──────────────────────┬────────────────────────┬──────────────────────┬────────────────────────┐
│ nametest_1_subject_mathstest_1_subject_physicstest_2_subject_mathstest_2_subject_physics │
│ ---------------                    │
│ stri64i64i64i64                    │
╞═══════╪══════════════════════╪════════════════════════╪══════════════════════╪════════════════════════╡
│ Cady9899100100                    │
│ Karen61586060                     │
└───────┴──────────────────────┴────────────────────────┴──────────────────────┴────────────────────────┘

After:

>>> df = pl.DataFrame(
...     {
...         "name": ["Cady", "Cady", "Karen", "Karen"],
...         "subject": ["maths", "physics", "maths", "physics"],
...         "test_1": [98, 99, 61, 58],
...         "test_2": [100, 100, 60, 60],
...     }
... )
>>> df.pivot(index='name', columns='subject', values=['test_1', 'test_2'])
┌───────┬──────────────┬────────────────┬──────────────┬────────────────┐
│ nametest_1_mathstest_1_physicstest_2_mathstest_2_physics │
│ ---------------            │
│ stri64i64i64i64            │
╞═══════╪══════════════╪════════════════╪══════════════╪════════════════╡
│ Cady9899100100            │
│ Karen61586060             │
└───────┴──────────────┴────────────────┴──────────────┴────────────────┘

@MarcoGorelli MarcoGorelli added the do not merge This pull requests should not be merged right now label May 23, 2024
@MarcoGorelli MarcoGorelli added this to the 1.0.0 milestone May 23, 2024
@github-actions github-actions bot added breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels May 23, 2024
@stinodego stinodego changed the title feat!: remove redundant column name when pivoting by multiple values feat!: Remove redundant column name when pivoting by multiple values May 23, 2024
@stinodego stinodego removed this from the 1.0.0 milestone May 23, 2024
@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 23, 2024 13:46
Copy link

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.44%. Comparing base (462bc8b) to head (d336eb6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16439      +/-   ##
==========================================
+ Coverage   81.43%   81.44%   +0.01%     
==========================================
  Files        1409     1409              
  Lines      184678   184678              
  Branches     2971     2971              
==========================================
+ Hits       150396   150416      +20     
+ Misses      33762    33742      -20     
  Partials      520      520              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stinodego stinodego removed the do not merge This pull requests should not be merged right now label Jun 4, 2024
@stinodego stinodego merged commit c6b434a into pola-rs:main Jun 4, 2024
33 checks passed
@stinodego stinodego changed the title feat!: Remove redundant column name when pivoting by multiple values feat!: Update pivot column names when pivoting by multiple values Jun 12, 2024
@stinodego stinodego changed the title feat!: Update pivot column names when pivoting by multiple values feat!: Update resulting column names in pivot when pivoting by multiple values Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pivoting with multiple values columns includes redundant information in column names
2 participants