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

Add DataFrame transform function #807

Closed
timsaucer opened this issue Aug 13, 2024 · 1 comment · Fixed by #839
Closed

Add DataFrame transform function #807

timsaucer opened this issue Aug 13, 2024 · 1 comment · Fixed by #839
Labels
enhancement New feature or request

Comments

@timsaucer
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Add a function akin to DataFrame.transform from pyspark. This gives an easy to use way to chain DataFrame transformations.

Describe the solution you'd like

It is common to write a python function that takes as it's input a DataFrame plus 0 or more arguments and return a DataFrame. It is convenient to be able to write functions this way and to chain them. For example

def add_something_cool(df: DataFrame) -> DataFrame:
    return df.with_column("the_answer", lit(42))

def add_another(df: DataFrame, col_name: str) -> DataFrame:
    return df.with_column(col_name, lit("another"))

df_original.transform(add_something_cool).transform(add_another, "second_col").show()

Describe alternatives you've considered

To do the above operation I would probably do it like

df = add_something_cool(df_original)
df = add_another(df, "second_col")
df.show()

Additional context

Documentation via Databricks for pyspark

@timsaucer timsaucer added the enhancement New feature or request label Aug 13, 2024
@timsaucer
Copy link
Contributor Author

timsaucer commented Aug 19, 2024

It might be as easy as

    def transform(self, func: Callable[..., DataFrame], *args: Any) -> DataFrame:
        return func(self, *args)

Seems to be working, but requires more testing

This was referenced Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant