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 a JupyterLite-powered interactive shell for the pandas website (reprise of #47428) #60758

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/docbuild-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ jobs:
- name: Build documentation
run: doc/make.py --warnings-are-errors

- name: Build the interactive terminal
working-directory: web/interactive_terminal
run: jupyter lite build

- name: Build documentation zip
run: doc/make.py zip_html

Expand Down
9 changes: 9 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ dependencies:
- requests
- pygments # Code highlighting

# web interactive REPL
# Pyodide kernel version 0.5.2 comes with Pyodide 0.27.1
# which in-turn comes with pandas 2.2.3:
Comment on lines +120 to +121
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this comment is attempting to convey - is there a reason this is important? Also, not sure if it's relevant but what comes with pandas 2.2.3 doesn't seem important here; this is used for dev envs, not releases.

# 1. https://jupyterlite-pyodide-kernel.readthedocs.io/en/stable/#compatibility
# 2. https://pyodide.org/en/stable/usage/packages-in-pyodide.html
# We constrain/pin here to avoid breaking changes on rebuilds.
Copy link
Member

Choose a reason for hiding this comment

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

We typically do not do this because hard pinning for some time and then doing a major upgrade is often harder than addressing each break as it comes in. Is there a reason we should take a different approach here?

- jupyterlite-core>=0.5.0,<0.6.0
- jupyterlite-pyodide-kernel=0.5.2

- pip:
- adbc-driver-postgresql>=0.10.0
- adbc-driver-sqlite>=0.8.0
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ feedparser
pyyaml
requests
pygments
jupyterlite-core>=0.5.0,<0.6.0
jupyterlite-pyodide-kernel==0.5.2
adbc-driver-postgresql>=0.10.0
adbc-driver-sqlite>=0.8.0
typing_extensions; python_version<"3.11"
Expand Down
38 changes: 38 additions & 0 deletions web/interactive_terminal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# The interactive `pandas` REPL

An interactive REPL to easily try `pandas` in the browser, powered by JupyterLite.

![image](https://user-images.githubusercontent.com/591645/175000291-e8c69f6f-5f2c-48d7-817c-cff05ab2cde9.png)

## Build

The interactive REPL is built with the `jupyter lite` CLI.

First make sure `jupyterlite` and a kernel are installed:

```bash
python -m pip install jupyterlite
python -m pip install jupyterlite-pyodide-kernel
```

Then in `web/interactive_terminal`, run the following command:

```bash
jupyter lite build
```

## Configuration

This folder contains configuration files for the interactive terminal powered by JupyterLite:

- `jupyter_lite_config.json`: build time configuration, used when building the assets with the `jupyter lite build` command
- `jupyter-lite.json` run time configuration applied when launching the application in the browser

This interactive `pandas` JupyterLite deployment enables a couple of optimizations to only include the `repl` app in the generated static assets, and disables source maps, which can make the assets smaller and faster to load, at the cost of
debugging capabilities.

To learn more about it, check out the JupyterLite documentation:

- Optimizations: https://jupyterlite.readthedocs.io/en/latest/howto/configure/advanced/optimizations.html
- JupyterLite schema: https://jupyterlite.readthedocs.io/en/latest/reference/schema-v0.html
- CLI reference: https://jupyterlite.readthedocs.io/en/latest/reference/cli.html
10 changes: 10 additions & 0 deletions web/interactive_terminal/jupyter-lite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jupyter-lite-schema-version": 0,
"jupyter-config-data": {
"appName": "Pandas REPL",
"appUrl": "./repl",
"enableMemoryStorage": true,
"settingsStorageDrivers": ["memoryStorageDriver"],
"contentsStorageDrivers": ["memoryStorageDriver"]
}
}
8 changes: 8 additions & 0 deletions web/interactive_terminal/jupyter_lite_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"LiteBuildConfig": {
"apps": ["repl"],
"no_unused_shared_packages": true,
"output_dir": "../build/lite",
"no_sourcemaps": true
}
}
25 changes: 21 additions & 4 deletions web/pandas/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ by [Wes McKinney](https://wesmckinney.com/), creator of pandas.

## Videos

<iframe width="560" height="315" frameborder="0"
src="https://www.youtube.com/embed/_T8LGqJtuGc"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
<iframe
src="https://www.youtube.com/embed/_T8LGqJtuGc"
style="width: 100%; max-width: 560px; height: 315px;"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>

## Cheat sheet

[pandas cheat sheet](https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf)

## Try pandas in your browser (experimental)

You can try pandas in your browser with the following interactive shell
without needing to install anything on your system.

**Please note it can take a while before the shell is initialised and ready to run commands.**
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a while can we give a estimate of how long.


**Running it requires a reasonable amount of bandwidth and resources, so it may not work properly on all devices or networks.**

<iframe
Copy link
Member

Choose a reason for hiding this comment

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

This will start loading on the Getting Started page, is that right? If so, I think we should perhaps move to its own page so that users don't have to spend the bandwidth.

src="./lite/repl/index.html?toolbar=1&kernel=python&execute=0&code=import%20pandas%20as%20pd%0Adf%20%3D%20pd.DataFrame%28%7B%22num_legs%22%3A%20%5B2%2C%204%5D%2C%20%22num_wings%22%3A%20%5B2%2C%200%5D%7D%2C%20index%3D%5B%22falcon%22%2C%20%22dog%22%5D%29%0Adf"
style="width: 100%; max-width: 650px; height: 600px; border: 1px solid #130753;"
></iframe>