pdit 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pdit/_demo.py ADDED
@@ -0,0 +1,103 @@
1
+ """
2
+ # Markdown
3
+
4
+ Top-level strings are _rendered_ as [Markdown](https://en.wikipedia.org/wiki/Markdown).
5
+ """
6
+
7
+ """
8
+ ## Expressions
9
+ """
10
+
11
+ 1 + 2
12
+
13
+ [x * 2 for x in [1, 2, 3]]
14
+
15
+ """
16
+ ## Matplotlib
17
+ """
18
+
19
+ import math
20
+ import matplotlib.pyplot as plt
21
+
22
+ x = [i * 0.1 for i in range(0, 63)]
23
+ y = [math.sin(v) for v in x]
24
+
25
+ # Wrap in `with plt.ioff():` to avoid every call to `plt.*` rendering a
26
+ # plot.
27
+ with plt.ioff():
28
+ plt.figure()
29
+ plt.plot(x, y)
30
+ plt.xlabel('x')
31
+ plt.ylabel('sin(x)')
32
+ plt.show()
33
+
34
+ """
35
+ ## Polars/Pandas
36
+
37
+ DataFrames are rendered as interactive tables.
38
+ """
39
+
40
+ import polars as pl
41
+
42
+ df = pl.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
43
+ df
44
+
45
+ """
46
+ ## GreatTables
47
+
48
+ [GreatTables](https://posit-dev.github.io/great-tables/) renders rich HTML tables.
49
+ """
50
+
51
+ from great_tables import GT
52
+
53
+ GT(df.head(5))
54
+
55
+ """
56
+ ## HTML representation
57
+
58
+ Classes that implement a `_repr_html_()` function returning HTML are rendered
59
+ as HTML.
60
+ """
61
+
62
+ class IrisSummary:
63
+ def __init__(self, df: pl.DataFrame):
64
+ self.df = df
65
+
66
+ def _repr_html_(self) -> str:
67
+ summary = (
68
+ self.df.group_by("species")
69
+ .agg(pl.col("sepal_length").mean().round(2).alias("mean"))
70
+ .sort("mean", descending=True)
71
+ )
72
+ max_mean = float(summary["mean"].max())
73
+ rows = "".join(
74
+ "<tr>"
75
+ f"<td style='padding-right:8px'>{species}</td>"
76
+ f"<td><meter min='0' max='{max_mean:.2f}' value='{mean:.2f}'></meter></td>"
77
+ f"<td style='padding-left:6px'>{mean:.2f}</td>"
78
+ "</tr>"
79
+ for species, mean in summary.iter_rows()
80
+ )
81
+ return (
82
+ "<div style='display:inline-block;border:1px solid #ddd;border-radius:8px;"
83
+ "padding:8px 10px;background:#fff;'>"
84
+ "<div style='font-weight:600;margin-bottom:6px'>Mean sepal length</div>"
85
+ "<table style='border-collapse:collapse;font-size:12px'>"
86
+ + rows
87
+ + "</table></div>"
88
+ )
89
+
90
+
91
+ IrisSummary(df)
92
+
93
+
94
+ """
95
+ ## IPython display objects
96
+
97
+ IPython [display objects](https://ipython.readthedocs.io/en/latest/api/generated/IPython.display.html)
98
+ are supported, e.g. images.
99
+ """
100
+
101
+ from IPython.display import Image
102
+
103
+ Image('pea.png')