Skip to content

Commit 0a4006f

Browse files
committed
Avoid displaying docstring column to spare vertical screen real estate
1 parent 5a69353 commit 0a4006f

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

polars/09_strings.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def _(mo):
250250

251251
@app.cell
252252
def _(expressions_df, pl):
253-
docstring_length_df = expressions_df.with_columns(
253+
docstring_length_df = expressions_df.select(
254+
'namespace',
255+
'member',
254256
docstring_len_chars=pl.col("docstring").str.len_chars(),
255257
docstring_len_bytes=pl.col("docstring").str.len_bytes(),
256258
)
@@ -446,7 +448,9 @@ def _(mo):
446448

447449
@app.cell
448450
def _(expressions_df, pl):
449-
expressions_df.with_columns(
451+
expressions_df.select(
452+
'namespace',
453+
'member',
450454
is_deprecated=pl.col('docstring').str.contains('.. deprecated', literal=True),
451455
has_parameters=pl.col('docstring').str.contains('Parameters'),
452456
has_examples=pl.col('docstring').str.contains('Examples'),
@@ -464,7 +468,9 @@ def _(mo):
464468

465469
@app.cell
466470
def _(expressions_df, pl):
467-
expressions_df.with_columns(
471+
expressions_df.select(
472+
'namespace',
473+
'member',
468474
has_reference=pl.col('docstring').str.contains_any(['See Also', 'https://'])
469475
)
470476
return
@@ -492,7 +498,9 @@ def _(mo):
492498

493499
@app.cell
494500
def _(expressions_df, pl):
495-
expressions_df.with_columns(
501+
expressions_df.select(
502+
'namespace',
503+
'member',
496504
variable_assignment_count=pl.col('docstring').str.count_matches(r'[a-zA-Z_][a-zA-Z0-9_]* = '),
497505
)
498506
return
@@ -506,7 +514,9 @@ def _(mo):
506514

507515
@app.cell
508516
def _(expressions_df, pl):
509-
expressions_df.with_columns(
517+
expressions_df.select(
518+
'namespace',
519+
'member',
510520
code_example_start=pl.col('docstring').str.find('>>>'),
511521
)
512522
return
@@ -533,8 +543,6 @@ def _(mo):
533543
@app.cell
534544
def _(expressions_df, pl, slice):
535545
sliced_df = expressions_df.select(
536-
# Original string
537-
"docstring",
538546
# First 25 chars
539547
docstring_head=pl.col("docstring").str.head(slice.value),
540548
# 50 chars after the first 25 chars
@@ -651,7 +659,7 @@ def _(mo):
651659

652660
@app.cell
653661
def _(expressions_df, pl):
654-
descriptions_df = expressions_df.select(
662+
descriptions_df = expressions_df.sample(5).select(
655663
description=pl.concat_str(
656664
[
657665
pl.lit("- Expression "),
@@ -717,8 +725,9 @@ def _(mo):
717725
@app.cell
718726
def _(expressions_df, pl):
719727
url_pattern = r'(https?://[^\s>]+)'
720-
expressions_df.with_columns(
721-
"docstring",
728+
expressions_df.select(
729+
'namespace',
730+
'member',
722731
url_match=pl.col('docstring').str.extract(url_pattern),
723732
url_matches=pl.col('docstring').str.extract_all(url_pattern),
724733
).filter(pl.col('url_match').is_not_null())
@@ -741,7 +750,9 @@ def _(mo):
741750

742751
@app.cell
743752
def _(expressions_df, pl):
744-
expressions_df.with_columns(
753+
expressions_df.select(
754+
'namespace',
755+
'member',
745756
example_df_shape=pl.col('docstring').str.extract_groups(r"shape:\s*\((?<height>\S+),\s*(?<width>\S+)\)"),
746757
)
747758
return
@@ -845,6 +856,8 @@ def _(mo):
845856
We make use of string expressions to extract the raw Python source code of examples from the docstrings and we leverage the interactive Marimo environment to enable the selection of expressions via a searchable dropdown and a fully functional code editor whose output is rendered with Marimo's rich display utilities.
846857
847858
In other words, we will use Polars to execute Polars. ❄️ How cool is that?
859+
860+
---
848861
"""
849862
)
850863
return
@@ -861,6 +874,7 @@ def _(
861874
):
862875
mo.vstack(
863876
[
877+
mo.md(f'### {expression.value}'),
864878
expression,
865879
mo.hstack([expression_description, expression_docs_link]),
866880
example_editor,

0 commit comments

Comments
 (0)