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: with_column(s)_renamed expression for DataFrame #3732

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

jessie-young
Copy link
Contributor

@jessie-young jessie-young commented Jan 28, 2025

issue #3705

Add with_column_renamed and with_columns_renamed to DataFrame API (no SQL).

def with_column_renamed(self, existing: str, new: str) -> "DataFrame":
    """Renames a column in the current DataFrame.

    Example:
        >>> import daft
        >>> df = daft.from_pydict({"x": [1, 2, 3], "y": [4, 5, 6]})
        >>> df.with_column_renamed("x", "foo").show()
        ╭───────┬───────╮
        │ foo   ┆ y     │
        │ ---   ┆ ---   │
        │ Int64 ┆ Int64 │
        ╞═══════╪═══════╡
        │ 1     ┆ 4     │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ 2     ┆ 5     │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ 3     ┆ 6     │
        ╰───────┴───────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    Args:
        existing (str): name of the existing column to rename
        new (str): new name for the column

    Returns:
        DataFrame: DataFrame with the column renamed.
    """
    
def with_columns_renamed(self, colsMap: Dict[str, str]) -> "DataFrame":
    """Renames multiple columns in the current DataFrame.

    Example:
        >>> import daft
        >>> df = daft.from_pydict({"x": [1, 2, 3], "y": [4, 5, 6]})
        >>> df.with_columns_renamed({"x": "foo", "y": "bar"}).show()
        ╭───────┬───────╮
        │ foo   ┆ bar   │
        │ ---   ┆ ---   │
        │ Int64 ┆ Int64 │
        ╞═══════╪═══════╡
        │ 1     ┆ 4     │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ 2     ┆ 5     │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ 3     ┆ 6     │
        ╰───────┴───────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)
    """

@jessie-young jessie-young requested a review from colin-ho January 28, 2025 01:38
@jessie-young jessie-young self-assigned this Jan 28, 2025
@jessie-young jessie-young changed the title Implement with_column(s)_renamed expression (#3705)[https://github.com/Eventual-Inc/Daft/issues/3705] feat: with_column(s)_renamed expression (#3705)[https://github.com/Eventual-Inc/Daft/issues/3705] Jan 28, 2025
@github-actions github-actions bot added the feat label Jan 28, 2025
@jessie-young jessie-young changed the title feat: with_column(s)_renamed expression (#3705)[https://github.com/Eventual-Inc/Daft/issues/3705] feat: with_column(s)_renamed expression for DataFrame Jan 28, 2025
Copy link

codspeed-hq bot commented Jan 28, 2025

CodSpeed Performance Report

Merging #3732 will not alter performance

Comparing with-columns_renamed (10aa453) with main (fec399e)

Summary

✅ 27 untouched benchmarks

@jessie-young jessie-young removed their assignment Jan 28, 2025
Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.59%. Comparing base (fec399e) to head (10aa453).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3732   +/-   ##
=======================================
  Coverage   77.58%   77.59%           
=======================================
  Files         729      729           
  Lines       92010    92042   +32     
=======================================
+ Hits        71389    71421   +32     
  Misses      20621    20621           
Files with missing lines Coverage Δ
daft/dataframe/dataframe.py 85.51% <100.00%> (+0.11%) ⬆️
daft/logical/builder.py 90.65% <100.00%> (+0.37%) ⬆️
src/daft-logical-plan/src/builder/mod.rs 91.81% <100.00%> (+0.15%) ⬆️

Copy link
Contributor

@colin-ho colin-ho left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM!

@jessie-young jessie-young merged commit 45f27c5 into main Jan 28, 2025
43 checks passed
@jessie-young jessie-young deleted the with-columns_renamed branch January 28, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants