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: add DataFrame|LazyFrame.unpivot method #1043

Merged
merged 6 commits into from
Sep 27, 2024
Merged

Conversation

FBruzzesi
Copy link
Member

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Plotly will most likely need this feature if they decide to use narwhals

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below.

@github-actions github-actions bot added the enhancement New feature or request label Sep 22, 2024
narwhals/dataframe.py Outdated Show resolved Hide resolved
Comment on lines +645 to +659
return self._from_native_frame(
pa.concat_tables(
[
pa.Table.from_arrays(
[
*[native_frame.column(idx_col) for idx_col in index_],
pa.array([on_col] * n_rows, pa.string()),
native_frame.column(on_col),
],
names=[*index_, variable_name, value_name],
)
for on_col in on_
]
)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Adapted from the following StackOverflow Answer

Comment on lines +743 to +744
var_name=variable_name if variable_name is not None else "variable",
value_name=value_name if value_name is not None else "value",
Copy link
Member Author

@FBruzzesi FBruzzesi Sep 22, 2024

Choose a reason for hiding this comment

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

That's because passing None (from the default of narwhals DataFrame) will overwrite the pandas default value of "value"

@FBruzzesi FBruzzesi changed the title feat: add unpivot for all backends feat: add DataFrame|LazyFrame.unpivot for all backends Sep 22, 2024
@FBruzzesi FBruzzesi changed the title feat: add DataFrame|LazyFrame.unpivot for all backends feat: add DataFrame|LazyFrame.unpivot method Sep 23, 2024
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

awesome!

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @FBruzzesi !

@MarcoGorelli MarcoGorelli merged commit a9963a6 into main Sep 27, 2024
25 checks passed
@FBruzzesi FBruzzesi deleted the feat/unpivot branch September 27, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants