-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtutorial_example.html
More file actions
897 lines (640 loc) · 42.3 KB
/
tutorial_example.html
File metadata and controls
897 lines (640 loc) · 42.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
<!DOCTYPE html>
<html lang="en" data-content_root="./" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="How to write an example for the gallery" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://skrub-data.github.io/stable/tutorial_example.html" />
<meta property="og:site_name" content="skrub" />
<meta property="og:description" content="This tutorial explains to new contributors how to format their examples so that they are properly rendered in the skrub documentation gallery. While examples are written in plain Python code, there..." />
<meta property="og:image" content="https://skrub-data.github.io/stable/_static/skrub.svg" />
<meta property="og:image:alt" content="skrub" />
<meta name="description" content="This tutorial explains to new contributors how to format their examples so that they are properly rendered in the skrub documentation gallery. While examples are written in plain Python code, there..." />
<title>How to write an example for the gallery — skrub</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
</script>
<!--
this give us a css class that will be invisible only if js is disabled
-->
<noscript>
<style>
.pst-js-only { display: none !important; }
</style>
</noscript>
<!-- Loaded before other Sphinx assets -->
<link href="_static/styles/theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link href="_static/styles/pydata-sphinx-theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=8f2a1f02" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Vibur" />
<link rel="stylesheet" type="text/css" href="_static/jupyterlite_sphinx.css?v=8ee2c72c" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery.css?v=d2d258e8" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-binder.css?v=f4aeca0c" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-dataframe.css?v=2082cf3c" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-rendered-html.css?v=1277b6f3" />
<link rel="stylesheet" type="text/css" href="_static/css/custom.css?v=7821ceae" />
<!-- So that users can add custom icons -->
<script src="_static/scripts/fontawesome.js?digest=8878045cc6db502f8baf"></script>
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf" />
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf" />
<script src="_static/documentation_options.js?v=486e5634"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
<script src="_static/copybutton.js?v=fd10adb8"></script>
<script src="_static/jupyterlite_sphinx.js?v=96e329c5"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'tutorial_example';</script>
<script>
DOCUMENTATION_OPTIONS.theme_version = '0.16.1';
DOCUMENTATION_OPTIONS.theme_switcher_json_url = 'https://raw.githubusercontent.com/skrub-data/skrub/main/doc/version.json';
DOCUMENTATION_OPTIONS.theme_switcher_version_match = '0.8.0';
DOCUMENTATION_OPTIONS.show_version_warning_banner =
true;
</script>
<script src="_static/scripts/sg_plotly_resize.js?v=a751aa24"></script>
<link rel="canonical" href="https://skrub-data.org/stable/tutorial_example.html" />
<link rel="icon" href="_static/skrub.svg"/>
<link rel="author" title="About these documents" href="about.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Release process" href="RELEASE_PROCESS.html" />
<link rel="prev" title="Contributing guide" href="CONTRIBUTING.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
<meta name="docsearch:version" content="0.8.0" />
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">
<div id="pst-skip-link" class="skip-link d-print-none"><a href="#main-content">Skip to main content</a></div>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>Back to top</button>
<dialog id="pst-search-dialog">
<form class="bd-search d-flex align-items-center"
action="search.html"
method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search"
class="form-control"
name="q"
placeholder="Search the docs ..."
aria-label="Search the docs ..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"/>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
</dialog>
<div class="pst-async-banner-revealer d-none">
<aside id="bd-header-version-warning" class="d-none d-print-none" aria-label="Version warning"></aside>
</div>
<header class="bd-header navbar navbar-expand-lg bd-navbar d-print-none">
<div class="bd-header__inner bd-page-width">
<button class="pst-navbar-icon sidebar-toggle primary-toggle" aria-label="Site navigation">
<span class="fa-solid fa-bars"></span>
</button>
<div class=" navbar-header-items__start">
<div class="navbar-item">
<a class="navbar-brand logo" href="index.html">
<img src="_static/skrub.svg" class="logo__image only-light" alt="skrub - Home"/>
<img src="_static/skrub.svg" class="logo__image only-dark pst-js-only" alt="skrub - Home"/>
</a></div>
</div>
<div class=" navbar-header-items">
<div class="me-auto navbar-header-items__center">
<div class="navbar-item">
<nav>
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item ">
<a class="nav-link nav-internal" href="install.html">
Install
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="documentation.html">
User Guide
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="reference/index.html">
API Reference
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="auto_examples/index.html">
Examples
</a>
</li>
<li class="nav-item dropdown">
<button class="btn dropdown-toggle nav-item" type="button"
data-bs-toggle="dropdown" aria-expanded="false"
aria-controls="pst-nav-more-links">
More
</button>
<ul id="pst-nav-more-links" class="dropdown-menu">
<li class=" ">
<a class="nav-link dropdown-item nav-internal" href="learning_materials.html">
Learning Materials
</a>
</li>
<li class=" ">
<a class="nav-link dropdown-item nav-internal" href="CHANGES.html">
Release history
</a>
</li>
<li class=" current active">
<a class="nav-link dropdown-item nav-internal" href="development.html">
Development
</a>
</li>
</ul>
</li>
</ul>
</nav></div>
</div>
<div class="navbar-header-items__end">
<div class="navbar-item navbar-persistent--container">
<button class="btn search-button-field search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
</div>
<div class="navbar-item">
<div class="version-switcher__container dropdown pst-js-only">
<button id="pst-version-switcher-button-2"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-2"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-2"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-2">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div></div>
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/skrub-data/skrub/" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
<li class="nav-item">
<a href="https://discord.gg/ABaPnm7fDC" title="Discord" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-discord fa-lg" aria-hidden="true"></i>
<span class="sr-only">Discord</span></a>
</li>
<li class="nav-item">
<a href="https://bsky.app/profile/skrub-data.bsky.social" title="Bluesky" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-bluesky fa-lg" aria-hidden="true"></i>
<span class="sr-only">Bluesky</span></a>
</li>
<li class="nav-item">
<a href="https://x.com/skrub_data" title="X (ex-Twitter)" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-x-twitter fa-lg" aria-hidden="true"></i>
<span class="sr-only">X (ex-Twitter)</span></a>
</li>
</ul></div>
</div>
</div>
<div class="navbar-persistent--mobile">
<button class="btn search-button-field search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
</div>
<button class="pst-navbar-icon sidebar-toggle secondary-toggle" aria-label="On this page">
<span class="fa-solid fa-outdent"></span>
</button>
</div>
</header>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<dialog id="pst-primary-sidebar-modal"></dialog>
<div id="pst-primary-sidebar" class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
<div class="sidebar-header-items__center">
<div class="navbar-item">
<nav>
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item ">
<a class="nav-link nav-internal" href="install.html">
Install
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="documentation.html">
User Guide
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="reference/index.html">
API Reference
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="auto_examples/index.html">
Examples
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="learning_materials.html">
Learning Materials
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="CHANGES.html">
Release history
</a>
</li>
<li class="nav-item current active">
<a class="nav-link nav-internal" href="development.html">
Development
</a>
</li>
</ul>
</nav></div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<div class="version-switcher__container dropdown pst-js-only">
<button id="pst-version-switcher-button-3"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-3"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-3"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-3">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div></div>
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/skrub-data/skrub/" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
<li class="nav-item">
<a href="https://discord.gg/ABaPnm7fDC" title="Discord" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-discord fa-lg" aria-hidden="true"></i>
<span class="sr-only">Discord</span></a>
</li>
<li class="nav-item">
<a href="https://bsky.app/profile/skrub-data.bsky.social" title="Bluesky" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-bluesky fa-lg" aria-hidden="true"></i>
<span class="sr-only">Bluesky</span></a>
</li>
<li class="nav-item">
<a href="https://x.com/skrub_data" title="X (ex-Twitter)" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-x-twitter fa-lg" aria-hidden="true"></i>
<span class="sr-only">X (ex-Twitter)</span></a>
</li>
</ul></div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
aria-label="Section Navigation">
<p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p>
<div class="bd-toc-item navbar-nav"><ul class="current nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="vision.html">Vision: Where is skrub heading?</a></li>
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
<li class="toctree-l1"><a class="reference internal" href="CONTRIBUTING.html">Contributing guide</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">How to write an example for the gallery</a></li>
<li class="toctree-l1"><a class="reference internal" href="RELEASE_PROCESS.html">Release process</a></li>
</ul>
</div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
<div class="sidebar-primary-item">
<div id="ethical-ad-placement"
class="flat"
data-ea-publisher="readthedocs"
data-ea-type="readthedocs-sidebar"
data-ea-manual="true">
</div></div>
</div>
</div>
<main id="main-content" class="bd-main" role="main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article d-print-none">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item">
<nav aria-label="Breadcrumb" class="d-print-none">
<ul class="bd-breadcrumbs">
<li class="breadcrumb-item breadcrumb-home">
<a href="index.html" class="nav-link" aria-label="Home">
<i class="fa-solid fa-home"></i>
</a>
</li>
<li class="breadcrumb-item"><a href="development.html" class="nav-link">Development</a></li>
<li class="breadcrumb-item active" aria-current="page"><span class="ellipsis">How to write an example for the gallery</span></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article">
<span class="target" id="tutorial-write-example"></span><section id="how-to-write-an-example-for-the-gallery">
<h1>How to write an example for the gallery<a class="headerlink" href="#how-to-write-an-example-for-the-gallery" title="Link to this heading">#</a></h1>
<p>This tutorial explains to new contributors how to format their examples so that
they are properly rendered in the skrub documentation gallery.</p>
<p>While examples are written in plain Python code, there are some quirks to be aware of
when writing them, due to the way Sphinx and the sphinx-gallery extension work.
This tutorial explains these quirks and how to work around them.</p>
<section id="location-of-the-examples">
<h2>Location of the examples<a class="headerlink" href="#location-of-the-examples" title="Link to this heading">#</a></h2>
<p>Once you decide on the subject of your example, start writing the code as a Python
script. Place the script in the <code class="docutils literal notranslate"><span class="pre">examples/</span></code> folder of the repository. The example
should be self-contained and runnable as a standalone script. The documentation is
built by executing the code and generating additional content from it.</p>
<p>The name of the file should start with a number, followed by an underscore,
and then a short description of the example. The number is used to order the examples
in the documentation. For instance, if your example is about using the
<a class="reference internal" href="reference/generated/skrub.TableVectorizer.html#skrub.TableVectorizer" title="skrub.TableVectorizer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TableVectorizer</span></code></a> class, you might want to name the file <code class="docutils literal notranslate"><span class="pre">01_table_vectorizer.py</span></code>.</p>
<p>Note that the <code class="docutils literal notranslate"><span class="pre">examples/</span></code> folder is covered by <code class="docutils literal notranslate"><span class="pre">pre-commit</span></code> hooks, which run
various checks on your code when you try to commit. These checks may block you from
pushing.</p>
<section id="dealing-with-typos-in-the-example">
<h3>Dealing with typos in the example<a class="headerlink" href="#dealing-with-typos-in-the-example" title="Link to this heading">#</a></h3>
<p>If your code includes any kind of intentional typo, for example if you are trying
to correct names by replacing a string with a typo with the new one, the
<code class="docutils literal notranslate"><span class="pre">codespell</span></code> hook will block your commit. To bypass this, update <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code>
by adding the typo to the <code class="docutils literal notranslate"><span class="pre">ignore-word-list</span></code> entry in the <code class="docutils literal notranslate"><span class="pre">tool.codespell</span></code>
section. After this, commit the updated <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code> file using
<code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span> <span class="pre">--no-verify</span></code> to bypass local checks so that following commits will
ignore the typos.
Note that without updating <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code>, the CI will still reject commits
with typos, as it runs the same hooks that are run locally.</p>
</section>
</section>
<section id="writing-the-example">
<h2>Writing the example<a class="headerlink" href="#writing-the-example" title="Link to this heading">#</a></h2>
<p>Your python script should start with a docstring that briefly explains what the example
is about. This docstring can contain multiple paragraphs and will be rendered
as an RST file in the documentation, so you can use RST syntax
in it.</p>
<p>Importantly, the first line of the docstring should be the title of the example,
not an RST directive (such as <code class="docutils literal notranslate"><span class="pre">..</span> <span class="pre">replace::</span></code> or <code class="docutils literal notranslate"><span class="pre">..</span> <span class="pre">note::</span></code>). Sphinx
adds a reference to the example at the top of the page using the file name as the
title. Adding a directive at the top of the docstring would prevent proper HTML
rendering.</p>
<p>This is an example of what the beginning of your example may look like:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">"""</span>
<span class="sd">Title of the example</span>
<span class="sd">====================</span>
<span class="sd">This is a brief description of the example. It can contain multiple paragraphs,</span>
<span class="sd">and it can use RST syntax.</span>
<span class="sd">.. note::</span>
<span class="sd"> You can use RST directives in the docstring, such as ``.. note::``,</span>
<span class="sd"> ``.. warning::``, ``.. seealso::``, etc.</span>
<span class="sd">After the definition of the title, you may also add directives such as</span>
<span class="sd">``.. replace::``, and they will be rendered properly. For example, you can add:</span>
<span class="sd">.. |TableVectorizer| replace:: :class:`~skrub.TableVectorizer`</span>
<span class="sd">"""</span>
</pre></div>
</div>
<p>Then, you can start writing the code for the example. The content of your Python script
should be a sequence of code cells, each delimited by a line starting with <code class="docutils literal notranslate"><span class="pre">#</span> <span class="pre">%%</span></code>.
These code cells may contain comments, which will be rendered as rst in the final
documentation.</p>
<p>After the docstring, write the code for your example as a sequence of code cells,
each delimited by a line starting with <code class="docutils literal notranslate"><span class="pre">#</span> <span class="pre">%%</span></code>. Comments in these cells will be
rendered as RST in the final documentation.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># %%</span>
<span class="c1"># This is a comment that will be rendered as markdown in the final documentation.</span>
<span class="c1"># You can use multiple lines for comments, and you can use RST syntax in them.</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pd</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">skrub</span><span class="w"> </span><span class="kn">import</span> <span class="n">TableVectorizer</span>
<span class="c1"># %%</span>
<span class="c1"># This is another code cell. You can write any python code here.</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
<span class="s2">"A"</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
<span class="s2">"B"</span><span class="p">:</span> <span class="p">[</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">]</span>
<span class="p">})</span>
<span class="n">tv</span> <span class="o">=</span> <span class="n">TableVectorizer</span><span class="p">()</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">tv</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="running-the-example">
<h2>Running the example<a class="headerlink" href="#running-the-example" title="Link to this heading">#</a></h2>
<p>Once you have written the code for the example (or while writing it), you can run
it to see how it looks in the final documentation. Depending on your setup, you
may need to install some dependencies. Refer to your IDE’s documentation for more
information on running interactive Python scripts. For example, VSCode documentation
is available <a class="reference external" href="https://code.visualstudio.com/docs/python/jupyter-support-py">here</a>.</p>
<p>Once you are happy with your example, you can submit a pull request to the repository,
following the instructions in the <a class="reference internal" href="CONTRIBUTING.html#contributing"><span class="std std-ref">contributing guide</span></a>.</p>
</section>
<section id="adding-cross-references">
<h2>Adding cross-references<a class="headerlink" href="#adding-cross-references" title="Link to this heading">#</a></h2>
<p>Adding cross-references to the documentation helps users find more information
about the concepts and functions used in your example. This step is optional, and
you may ask the maintainers for help on which cross-references to add. Good
cross-references include relevant user guide sections, the documentation of the
objects used in the example (like the <a class="reference internal" href="reference/generated/skrub.TableVectorizer.html#skrub.TableVectorizer" title="skrub.TableVectorizer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TableVectorizer</span></code></a>), or other examples.</p>
<p>You can add cross-references in the docstring and comments of your example in several ways:</p>
<ul class="simple">
<li><p>You can add references to the objects in the skrub API using the <code class="docutils literal notranslate"><span class="pre">:class:`~skrub.ClassName`</span></code>
or <code class="docutils literal notranslate"><span class="pre">:func:`~skrub.function_name`</span></code> directives.</p></li>
<li><p>If your example uses the same objects multiple times, you can define a replacement at the top
of the docstring using the <code class="docutils literal notranslate"><span class="pre">..</span> <span class="pre">replace::</span></code> directive, and then use the replacement
instead of the full directive.</p></li>
<li><p>You can also add references to other sections of the documentation using the
<code class="docutils literal notranslate"><span class="pre">:ref:`label`</span></code> directive, where <code class="docutils literal notranslate"><span class="pre">label</span></code> is the label of the section you want to reference.</p></li>
</ul>
<p>For example, if your example uses the <a class="reference internal" href="reference/generated/skrub.TableVectorizer.html#skrub.TableVectorizer" title="skrub.TableVectorizer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TableVectorizer</span></code></a> class multiple times, define
a replacement at the top of the docstring. You may also want to add a reference
to the user guide section about the <a class="reference internal" href="reference/generated/skrub.TableVectorizer.html#skrub.TableVectorizer" title="skrub.TableVectorizer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TableVectorizer</span></code></a> class. This can be done as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">"""</span>
<span class="sd">Title of the example</span>
<span class="sd">====================</span>
<span class="sd">.. |TableVectorizer| replace:: :class:`~skrub.TableVectorizer`</span>
<span class="sd">This example demonstrates how to use the |TableVectorizer| class to vectorize a dataframe.</span>
<span class="sd">See the :ref:`user_guide_building_pipeline_index` guide for more information about the |TableVectorizer| class.</span>
<span class="sd">"""</span>
<span class="c1"># %%</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pd</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">skrub</span><span class="w"> </span><span class="kn">import</span> <span class="n">TableVectorizer</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
<span class="s2">"A"</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
<span class="s2">"B"</span><span class="p">:</span> <span class="p">[</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">]</span>
<span class="p">})</span>
<span class="n">tv</span> <span class="o">=</span> <span class="n">TableVectorizer</span><span class="p">()</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">tv</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
</pre></div>
</div>
<p>You may find more information on the cross-references in the
<a class="reference external" href="https://www.sphinx-doc.org/en/master/usage/referencing.html">official Sphinx documentation</a>.</p>
</section>
<section id="generating-the-new-documentation">
<h2>Generating the new documentation<a class="headerlink" href="#generating-the-new-documentation" title="Link to this heading">#</a></h2>
<p>Once you have written your example and added any necessary cross-references, you can
generate the new documentation to see how it looks. This can be done in two ways:</p>
<ul class="simple">
<li><p>You can run the commands <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">html</span></code> or <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">html-noplot</span></code> in the <code class="docutils literal notranslate"><span class="pre">doc/</span></code>
folder of the repository to generate the HTML documentation for the entire project.</p></li>
<li><p>Alternatively, you can use <code class="docutils literal notranslate"><span class="pre">pixi</span> <span class="pre">run</span> <span class="pre">-e</span> <span class="pre">doc</span> <span class="pre">build-doc</span></code> or <code class="docutils literal notranslate"><span class="pre">pixi</span> <span class="pre">run</span> <span class="pre">-e</span> <span class="pre">doc</span> <span class="pre">build-doc-quick</span></code>
from the root folder to generate the documentation. The advantage of using <code class="docutils literal notranslate"><span class="pre">pixi</span></code> is that
it automatically sets up a virtual environment with the necessary dependencies, so you
don’t need to worry about installing them manually.</p></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">html</span></code> and <code class="docutils literal notranslate"><span class="pre">pixi</span> <span class="pre">run</span> <span class="pre">-e</span> <span class="pre">doc</span> <span class="pre">build-doc</span></code> commands generate complete
documentation by executing all example code. The <code class="docutils literal notranslate"><span class="pre">-noplot</span></code> (or <code class="docutils literal notranslate"><span class="pre">-quick</span></code>)
versions skip code execution, making documentation generation much faster. Use
these faster versions to check formatting when you’ve already tested your example
code locally.</p>
<p>The CI pipeline will always run the full documentation build, so you can safely
use <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">html-noplot</span></code> or <code class="docutils literal notranslate"><span class="pre">pixi</span> <span class="pre">run</span> <span class="pre">-e</span> <span class="pre">doc</span> <span class="pre">build-doc-quick</span></code> for local testing.</p>
<p>After generating the documentation, open the <code class="docutils literal notranslate"><span class="pre">index.html</span></code> file in the <code class="docutils literal notranslate"><span class="pre">doc/_build/html/</span></code>
folder with a web browser to review the results. Check that:</p>
<ul class="simple">
<li><p>Section titles are properly formatted.</p></li>
<li><p>Any formatting in docstrings or comments is rendered as intended. For example,
Sphinx uses spaces to delimit lists and code blocks, so if you have them in the
example, make sure that they render correctly.</p></li>
<li><p>Cross-references are working. You can check the logs of the Sphinx
generation to see if there are any broken references.</p></li>
</ul>
</section>
<section id="linking-your-work-to-examples-already-in-the-documentation">
<h2>Linking your work to examples already in the documentation<a class="headerlink" href="#linking-your-work-to-examples-already-in-the-documentation" title="Link to this heading">#</a></h2>
<p>After generating the documentation, you may want to add references to your example
in other relevant parts of the documentation. This helps users find your example
when reading about related topics.</p>
<p>This step is done after generating the documentation because you need the final
reference name, which is created dynamically from your file name. For example,
if your file is named <code class="docutils literal notranslate"><span class="pre">99_my_example.py</span></code>:</p>
<ol class="arabic simple">
<li><p>The generated files will be in <code class="docutils literal notranslate"><span class="pre">doc/auto_examples</span></code></p></li>
<li><p>A reference file will be created at <code class="docutils literal notranslate"><span class="pre">doc/auto_examples/99_my_example.rst</span></code></p></li>
<li><p>The reference label will be <code class="docutils literal notranslate"><span class="pre">..</span> <span class="pre">_sphx_glr_auto_examples_99_my_example.py</span></code></p></li>
</ol>
<p>To link to your example from other documentation pages, use:</p>
<div class="highlight-rst notranslate"><div class="highlight"><pre><span></span><span class="na">:ref:</span><span class="nv">`sphx_glr_auto_examples_99_my_example.py`</span>
</pre></div>
</div>
</section>
<section id="merging-your-example">
<h2>Merging your example<a class="headerlink" href="#merging-your-example" title="Link to this heading">#</a></h2>
<p>Finally, if everything looks good, commit your changes and submit a pull request
to the repository. For more information, see the <a class="reference internal" href="CONTRIBUTING.html#contributing"><span class="std std-ref">contributing guide</span></a>.</p>
<p>Your PR will be reviewed by the maintainers, who may suggest changes or improvements.
Once approved, it will be merged into the main branch, and your example will
become part of the official documentation. Thank you!</p>
</section>
</section>
</article>
<footer class="prev-next-footer d-print-none">
<div class="prev-next-area">
<a class="left-prev"
href="CONTRIBUTING.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Contributing guide</p>
</div>
</a>
<a class="right-next"
href="RELEASE_PROCESS.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Release process</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
</div>
</footer>
</div>
<dialog id="pst-secondary-sidebar-modal"></dialog>
<div id="pst-secondary-sidebar" class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">
<div class="sidebar-secondary-item">
<div
id="pst-page-navigation-heading-2"
class="page-toc tocsection onthispage">
<i class="fa-solid fa-list"></i> On this page
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#location-of-the-examples">Location of the examples</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#dealing-with-typos-in-the-example">Dealing with typos in the example</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#writing-the-example">Writing the example</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#running-the-example">Running the example</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#adding-cross-references">Adding cross-references</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#generating-the-new-documentation">Generating the new documentation</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#linking-your-work-to-examples-already-in-the-documentation">Linking your work to examples already in the documentation</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#merging-your-example">Merging your example</a></li>
</ul>
</nav></div>
<div class="sidebar-secondary-item">
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/tutorial_example.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div></div>
</div></div>
</div>
<footer class="bd-footer-content">
</footer>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script defer src="_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf"></script>
<script defer src="_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf"></script>
<footer class="bd-footer">
<div class="bd-footer__inner bd-page-width">
<div class="footer-items__start">
<div class="footer-item">Financial support from <a href="https://inria.fr">inria</a> and <a
href="https://probabl.ai">:probabl.</a></div>
</div>
<div class="footer-items__end">
<div class="footer-item">
<p class="theme-version">
<!-- # L10n: Setting the PST URL as an argument as this does not need to be localized -->
Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> 0.16.1.
</p></div>
</div>
</div>
</footer>
</body>
</html>