Skip to content

Add Python/pandas equivalent tab to all playground pages with CI validation - #93

Merged
mrjf merged 13 commits into
mainfrom
copilot/add-python-equivalent-tab
Apr 10, 2026
Merged

Add Python/pandas equivalent tab to all playground pages with CI validation#93
mrjf merged 13 commits into
mainfrom
copilot/add-python-equivalent-tab

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Every playground code block now has a switchable TypeScript/Python tab showing the equivalent pandas code side-by-side. Python tab is background by default. All 186 Python examples are validated in CI on every push.

Runtime (playground-runtime.js)

  • Detects <textarea class="playground-python"> siblings and renders a tab bar (TypeScript | Python)
  • Python view is read-only <pre> — switches hide the editor/run controls
  • Execution timing displayed after each run (e.g. ⏱ 2.3ms)
  • Tab CSS injected dynamically so all 25 pages inherit it

Playground pages (25 files, 186 blocks)

Each playground-editor textarea now has a hidden playground-python sibling with idiomatic pandas equivalent:

<textarea class="playground-editor" spellcheck="false">import { Series } from "tsb";
const s = new Series({ data: [10, 20, 30] });
console.log(s.toString());</textarea>
<textarea class="playground-python" style="display:none">import pandas as pd
s = pd.Series([10, 20, 30])
print(s.to_string())</textarea>

CI validation

  • scripts/validate-python-examples.py — extracts Python blocks from HTML, runs each with pandas, reports failures with timing
  • ci.yml — new validate-python-examples job runs on PRs
  • pages.yml — Python validation gate before Pages deployment

All examples target pandas 3.0+ (e.g. io.StringIO for read_json, no dropna param on stack()).

Copilot AI and others added 12 commits April 10, 2026 15:59
…ages

Add hidden <textarea class='playground-python'> elements after each
playground-editor textarea in dtype.html (7 blocks) and dataframe.html
(11 blocks). Each contains the equivalent pandas/numpy Python code
for the TypeScript example shown in the editor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Add <textarea class="playground-python"> sibling elements after each
playground-editor with equivalent Python/pandas code for:
- index-playground.html (9 blocks): Index creation, properties, label
  lookup, set operations, sorting, manipulation, missing values,
  RangeIndex, and scratch pad
- groupby.html (11 blocks): sum, mean/min/max, count, std, first/last,
  size/ngroups, agg, transform, apply, filter, and scratch pad

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
…d pages

Add hidden <textarea class="playground-python"> elements after each
playground-editor block containing equivalent pandas code:
- concat.html: 6 blocks with pd.concat() equivalents
- merge.html: 5 blocks with pd.merge() equivalents
- csv.html: 7 blocks with pd.read_csv()/to_csv() equivalents

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Add hidden playground-python textareas after each playground-editor
textarea in string_accessor.html (9 blocks), datetime_accessor.html
(8 blocks), and describe.html (7 blocks) with equivalent pandas code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Add hidden <textarea class="playground-python"> elements after each
playground-editor in json.html (7), corr.html (4), rolling.html (8),
and ewm.html (9) with equivalent pandas code using proper Python
conventions (snake_case, print(), pd.read_json, df.to_json, etc.).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
…layground pages

Add hidden <textarea class='playground-python'> elements after each
playground-editor textarea with equivalent pandas code:
- melt.html: 4 blocks (pd.melt with id_vars, value_vars, var_name, value_name)
- pivot.html: 5 blocks (df.pivot, pd.pivot_table with aggfunc, fill_value)
- stack_unstack.html: 6 blocks (df.stack, s.unstack with dropna, fill_value)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
…ground pages

Add hidden playground-python textareas with equivalent pandas code after
each playground-editor textarea in rank.html (8 blocks), nlargest.html
(8 blocks), and cum_ops.html (8 blocks).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Add hidden <textarea class="playground-python"> elements after each
playground-editor textarea in elem_ops.html (7 blocks),
value_counts.html (6 blocks), multi_index.html (8 blocks), and
cat_accessor.html (8 blocks).

Each Python block mirrors the corresponding TypeScript example using
idiomatic pandas APIs (snake_case methods, keyword arguments,
print() instead of console.log(), Python literals).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
- json.html: Add import io and wrap pd.read_json() string args with
  io.StringIO() in blocks 1-5 and 7
- stack_unstack.html: Remove deprecated dropna parameter from
  df.stack() calls; chain .dropna() after stack where needed
- csv.html: Fix skiprows=2 to skiprows=range(1, 3) to preserve header
  row in block 5

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
- index-playground.html: Replace .to_list() with .tolist() for numpy
  array results from isin(), argsort(), isna(), notna()
- ewm.html: Add raw=True to ewm().apply() for pandas 3.0 compatibility
- nlargest.html: Replace nlargest/nsmallest on string Series with
  sort_values().head() which works in pandas

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Python equivalent tab for documentation and playground Add Python/pandas equivalent tab to all playground pages with CI validation Apr 10, 2026
Copilot AI requested a review from mrjf April 10, 2026 16:43
Copilot finished work on behalf of mrjf April 10, 2026 16:43
@mrjf
mrjf marked this pull request as ready for review April 10, 2026 17:06
@mrjf
mrjf merged commit 9a11f1f into main Apr 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In pages site documentation / playground, have a tab for python equivalent

2 participants