-
Notifications
You must be signed in to change notification settings - Fork 121
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
docs: use type hints + from_native/to_native in dataframe.py #1425
docs: use type hints + from_native/to_native in dataframe.py #1425
Conversation
narwhals/dataframe.py
Outdated
>>> data = {"a": [1, 2, 3], "ba": [4, 5, 6]} | ||
>>> df_pd = pd.DataFrame(data) | ||
>>> df_pl = pl.DataFrame(data) | ||
|
||
Let's define a dataframe-agnostic function: | ||
|
||
>>> @nw.narwhalify | ||
... def func(df): | ||
>>> def agnostic_pipe(df_native: IntoFrame) -> IntoFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use IntoFrameT
? this signals that we return the same kind of object that we started with
narwhals/dataframe.py
Outdated
>>> @nw.narwhalify | ||
... def func(df): | ||
... return df.drop_nulls() | ||
>>> def agnostic_drop_nulls(df_native: IntoFrame) -> IntoFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for updating! just come minor comments left
narwhals/dataframe.py
Outdated
>>> @nw.narwhalify | ||
... def func(df): | ||
... return df.pipe(lambda _df: _df.select("a")) | ||
>>> def agnostic_pipe(df_native: IntoFrame) -> IntoFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntoFrameT
narwhals/dataframe.py
Outdated
>>> @nw.narwhalify | ||
... def func(df): | ||
... return df.drop_nulls() | ||
>>> def agnostic_drop_nulls(df_native: IntoFrame) -> IntoFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
narwhals/dataframe.py
Outdated
>>> @nw.narwhalify | ||
... def func(df): | ||
... return df.with_row_index() | ||
>>> def agnostic_with_row_index(df_native: IntoFrame) -> IntoFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @raisadz !
What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below