petergy commited on
Commit
0a4006f
·
1 Parent(s): 5a69353

Avoid displaying `docstring` column to spare vertical screen real estate

Browse files
Files changed (1) hide show
  1. polars/09_strings.py +25 -11
polars/09_strings.py CHANGED
@@ -250,7 +250,9 @@ def _(mo):
250
 
251
  @app.cell
252
  def _(expressions_df, pl):
253
- docstring_length_df = expressions_df.with_columns(
 
 
254
  docstring_len_chars=pl.col("docstring").str.len_chars(),
255
  docstring_len_bytes=pl.col("docstring").str.len_bytes(),
256
  )
@@ -446,7 +448,9 @@ def _(mo):
446
 
447
  @app.cell
448
  def _(expressions_df, pl):
449
- expressions_df.with_columns(
 
 
450
  is_deprecated=pl.col('docstring').str.contains('.. deprecated', literal=True),
451
  has_parameters=pl.col('docstring').str.contains('Parameters'),
452
  has_examples=pl.col('docstring').str.contains('Examples'),
@@ -464,7 +468,9 @@ def _(mo):
464
 
465
  @app.cell
466
  def _(expressions_df, pl):
467
- expressions_df.with_columns(
 
 
468
  has_reference=pl.col('docstring').str.contains_any(['See Also', 'https://'])
469
  )
470
  return
@@ -492,7 +498,9 @@ def _(mo):
492
 
493
  @app.cell
494
  def _(expressions_df, pl):
495
- expressions_df.with_columns(
 
 
496
  variable_assignment_count=pl.col('docstring').str.count_matches(r'[a-zA-Z_][a-zA-Z0-9_]* = '),
497
  )
498
  return
@@ -506,7 +514,9 @@ def _(mo):
506
 
507
  @app.cell
508
  def _(expressions_df, pl):
509
- expressions_df.with_columns(
 
 
510
  code_example_start=pl.col('docstring').str.find('>>>'),
511
  )
512
  return
@@ -533,8 +543,6 @@ def _(mo):
533
  @app.cell
534
  def _(expressions_df, pl, slice):
535
  sliced_df = expressions_df.select(
536
- # Original string
537
- "docstring",
538
  # First 25 chars
539
  docstring_head=pl.col("docstring").str.head(slice.value),
540
  # 50 chars after the first 25 chars
@@ -651,7 +659,7 @@ def _(mo):
651
 
652
  @app.cell
653
  def _(expressions_df, pl):
654
- descriptions_df = expressions_df.select(
655
  description=pl.concat_str(
656
  [
657
  pl.lit("- Expression "),
@@ -717,8 +725,9 @@ def _(mo):
717
  @app.cell
718
  def _(expressions_df, pl):
719
  url_pattern = r'(https?://[^\s>]+)'
720
- expressions_df.with_columns(
721
- "docstring",
 
722
  url_match=pl.col('docstring').str.extract(url_pattern),
723
  url_matches=pl.col('docstring').str.extract_all(url_pattern),
724
  ).filter(pl.col('url_match').is_not_null())
@@ -741,7 +750,9 @@ def _(mo):
741
 
742
  @app.cell
743
  def _(expressions_df, pl):
744
- expressions_df.with_columns(
 
 
745
  example_df_shape=pl.col('docstring').str.extract_groups(r"shape:\s*\((?<height>\S+),\s*(?<width>\S+)\)"),
746
  )
747
  return
@@ -845,6 +856,8 @@ def _(mo):
845
  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.
846
 
847
  In other words, we will use Polars to execute Polars. ❄️ How cool is that?
 
 
848
  """
849
  )
850
  return
@@ -861,6 +874,7 @@ def _(
861
  ):
862
  mo.vstack(
863
  [
 
864
  expression,
865
  mo.hstack([expression_description, expression_docs_link]),
866
  example_editor,
 
250
 
251
  @app.cell
252
  def _(expressions_df, pl):
253
+ docstring_length_df = expressions_df.select(
254
+ 'namespace',
255
+ 'member',
256
  docstring_len_chars=pl.col("docstring").str.len_chars(),
257
  docstring_len_bytes=pl.col("docstring").str.len_bytes(),
258
  )
 
448
 
449
  @app.cell
450
  def _(expressions_df, pl):
451
+ expressions_df.select(
452
+ 'namespace',
453
+ 'member',
454
  is_deprecated=pl.col('docstring').str.contains('.. deprecated', literal=True),
455
  has_parameters=pl.col('docstring').str.contains('Parameters'),
456
  has_examples=pl.col('docstring').str.contains('Examples'),
 
468
 
469
  @app.cell
470
  def _(expressions_df, pl):
471
+ expressions_df.select(
472
+ 'namespace',
473
+ 'member',
474
  has_reference=pl.col('docstring').str.contains_any(['See Also', 'https://'])
475
  )
476
  return
 
498
 
499
  @app.cell
500
  def _(expressions_df, pl):
501
+ expressions_df.select(
502
+ 'namespace',
503
+ 'member',
504
  variable_assignment_count=pl.col('docstring').str.count_matches(r'[a-zA-Z_][a-zA-Z0-9_]* = '),
505
  )
506
  return
 
514
 
515
  @app.cell
516
  def _(expressions_df, pl):
517
+ expressions_df.select(
518
+ 'namespace',
519
+ 'member',
520
  code_example_start=pl.col('docstring').str.find('>>>'),
521
  )
522
  return
 
543
  @app.cell
544
  def _(expressions_df, pl, slice):
545
  sliced_df = expressions_df.select(
 
 
546
  # First 25 chars
547
  docstring_head=pl.col("docstring").str.head(slice.value),
548
  # 50 chars after the first 25 chars
 
659
 
660
  @app.cell
661
  def _(expressions_df, pl):
662
+ descriptions_df = expressions_df.sample(5).select(
663
  description=pl.concat_str(
664
  [
665
  pl.lit("- Expression "),
 
725
  @app.cell
726
  def _(expressions_df, pl):
727
  url_pattern = r'(https?://[^\s>]+)'
728
+ expressions_df.select(
729
+ 'namespace',
730
+ 'member',
731
  url_match=pl.col('docstring').str.extract(url_pattern),
732
  url_matches=pl.col('docstring').str.extract_all(url_pattern),
733
  ).filter(pl.col('url_match').is_not_null())
 
750
 
751
  @app.cell
752
  def _(expressions_df, pl):
753
+ expressions_df.select(
754
+ 'namespace',
755
+ 'member',
756
  example_df_shape=pl.col('docstring').str.extract_groups(r"shape:\s*\((?<height>\S+),\s*(?<width>\S+)\)"),
757
  )
758
  return
 
856
  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.
857
 
858
  In other words, we will use Polars to execute Polars. ❄️ How cool is that?
859
+
860
+ ---
861
  """
862
  )
863
  return
 
874
  ):
875
  mo.vstack(
876
  [
877
+ mo.md(f'### {expression.value}'),
878
  expression,
879
  mo.hstack([expression_description, expression_docs_link]),
880
  example_editor,