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

improvement: auto-encoding pandas/numpy, mo.ui.table takes in Dataframe #197

Merged
merged 4 commits into from
Oct 12, 2023

Conversation

mscolnick
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Oct 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 4:04pm
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 4:04pm


def __init__(
self,
data: TableData,
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's kind of ugly, but can you inline this type? That makes the docs / autocomplete more useful to the user.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that might also make the type error in the docs CI go away. Otherwise you can replace the | with Union

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to union, and inline here (where its used in the docs), but kept everywhere else DRYed up


class WebComponentEncoder(JSONEncoder):
"""Custom JSON encoder for WebComponents"""

def default(self, obj: Any) -> Any:
# Handle numpy objects
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!


**Initialization Args.**

- `data`: a list of values representing a column, or a list of dicts
Copy link
Contributor

Choose a reason for hiding this comment

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

update doc to mention that data can be a dataframe? I'd start with that.

"A pandas dataframe, or a list of values representing a column, or a list of dicts ...

```python
# df is a Pandas dataframe
table = mo.ui.table(
data=df.to_dict('records'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove to_dict

Comment on lines 29 to 30
list[dict[str, str]],
Sequence[str | int | float | bool | MIME | None],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need list[dict[str, str]]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically our values in the dicts need to be homegenious. this makes the typings super ugly, so i removed this and just type ignored the response from to_dicts

akshayka
akshayka previously approved these changes Oct 12, 2023
@mscolnick mscolnick merged commit d089776 into main Oct 12, 2023
19 checks passed
@mscolnick mscolnick deleted the ms/table-pandas branch October 12, 2023 16:10
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants