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(data frame): Add generic type support via render return value #1502

Merged
merged 10 commits into from
Jul 11, 2024

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Jul 9, 2024

Add support for @render.data_frame to know what the real type should be for .data_value(), .data(), and any other data related methods.

Ex: Both first_df and second_df are aware that the return value of the render method has an underlying data type of [pandas.]DataFrame. This also works for polars.DataFrame.

# app.py
from palmerpenguins import load_penguins_raw  # pyright: ignore[reportMissingTypeStubs]

from shiny.express import render


@render.data_frame
def first_df():
    return render.DataGrid(data=load_penguins_raw())


@render.data_frame
def second_df():
    return first_df.data_view(selected=True)


@render.code
def code():
    return str(second_df.data())

Screenshot 2024-07-09 at 2 46 55 AM
Screenshot 2024-07-09 at 2 47 03 AM

TODO:

  • Fix PandasCompatible type. The __new__ of DataGrid and DataTable does not convey that it is converted to a pandas.DataFrame.
    • Solution ✅ : Users call df.to_pandas() to convert their data to pandas
      Screenshot 2024-07-09 at 3 05 18 AM

    • Bad workaround: Give type to @render.data_frame[PdDataFrame]
      Screenshot 2024-07-09 at 3 03 10 AM

schloerke added 4 commits July 9, 2024 01:23
* Added `TypeIs` to typing extensions
* Using `__new__` to init class with `.to_pandas()` result; Overloading `__new__` gives proper typing; Next: Make base class to inherit from
* Next: DataGrid impl using new base class
…turn types. PandasCompatible still has issues
@schloerke schloerke added the data frame Related to @render.data_frame label Jul 9, 2024
@schloerke schloerke added this to the v1.0.0 milestone Jul 9, 2024
@schloerke schloerke marked this pull request as ready for review July 10, 2024 15:55
@schloerke schloerke added this pull request to the merge queue Jul 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 10, 2024
@schloerke schloerke added this pull request to the merge queue Jul 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 10, 2024
@schloerke schloerke enabled auto-merge July 10, 2024 20:48
@schloerke schloerke added this pull request to the merge queue Jul 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 10, 2024
@schloerke schloerke merged commit ef0f9f6 into main Jul 11, 2024
31 checks passed
@schloerke schloerke deleted the df_generic_types branch July 11, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data frame Related to @render.data_frame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant