Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Sep 23, 2023
1 parent 3d149f1 commit 4bba14a
Show file tree
Hide file tree
Showing 20 changed files with 407 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="book/testing/index.html">11. Testing in Python</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-11"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="book/testing/Chapter.html">11.1. Pytest</a></li>
<li class="toctree-l2"><a class="reference internal" href="book/testing/Chapter.html">11.1. Testing</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="book/Miscellaneous/index.html">12. Miscellaneous</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-12"><i class="fa-solid fa-chevron-down"></i></label><ul>
Expand Down
80 changes: 80 additions & 0 deletions _sources/book/cooltools/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,86 @@
")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Speedtests via CLI with `speedtest-cli`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to test your internet bandwidth via your CLI\n",
"\n",
"try `speedtest-cli`.\n",
"\n",
"`speedtest-cli` tests your internet bandwidth via speedtest(dot)net.\n",
"\n",
"It’s installable via pip."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install speedtest-cli"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!speedtest-cli"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Minimalistic Database for Python with `tinydb`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Do you search for a minimalistic document-oriented database in Python?\n",
"\n",
"Use `tinydb`.\n",
"\n",
"`tinydb` is written in pure Python and offers a lightweight document-oriented database.\n",
"\n",
"It’s perfect for small apps and hobby projects."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install tinydb"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tinydb import TinyDB, Query\n",
"\n",
"db = TinyDB('/path/to/db.json')\n",
"db.insert({'int': 1, 'char': 'a'})\n",
"db.insert({'int': 1, 'char': 'b'})"
]
}
],
"metadata": {
Expand Down
40 changes: 40 additions & 0 deletions _sources/book/machinelearning/eda.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,46 @@
" size=\"pop\")\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mosaic Plots with `Matplotlib`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can create a mosaic of subplots in Matplotlib.\n",
"\n",
"`plt.subplot_mosaic()` allows you to arrange multiple subplots in a grid-like fashion, specifying their positions and sizes using a string.\n",
"\n",
"A powerful function to control your subplots."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"# Define the layout of subplots\n",
"layout = '''\n",
" AAE\n",
" C.E\n",
" '''\n",
"\n",
"fig = plt.figure(constrained_layout=True)\n",
"axd = fig.subplot_mosaic(layout)\n",
"\n",
"for key, ax in axd.items():\n",
" ax.plot([1, 2, 3, 4], [1, 4, 9, 16])\n",
" ax.set_title(f\"Plot {key}\")"
]
}
],
"metadata": {
Expand Down
30 changes: 30 additions & 0 deletions _sources/book/pandas/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,36 @@
"\n",
"sales_df.style.applymap(coloring, subset=['Revenue'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Precision of Displayed Floats"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In Pandas, you can control the precision of the displayed values.\n",
"\n",
"Just use the .set_option() function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"pd.set_option('display.precision', 2)\n",
"\n",
"data = {'Value': [1.2343129, 5.8956701, 6.224289]}\n",
"df = pd.DataFrame(data)"
]
}
],
"metadata": {
Expand Down
41 changes: 41 additions & 0 deletions _sources/book/pythontricks/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,47 @@
"\n",
"dict_1 | dict_2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Switch Case Statements in Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Did you know Python has switch-cases too?\n",
"\n",
"They’re called match-case and it was introduced in Python 3.10+.\n",
"\n",
"It allows you to perform (complex) pattern matching on values and execute code blocks based on the matched patterns."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def match_example(value):\n",
" match value:\n",
" case 1:\n",
" print(\"Value is 1\")\n",
"\n",
" case 2 | 3:\n",
" print(\"Value is 2 or 3\")\n",
" \n",
" case 4:\n",
" print(\"Value is 4\")\n",
" \n",
" case _:\n",
" print(\"Value is something else\")\n",
"\n",
"match_example(2)"
]
}
],
"metadata": {
Expand Down
44 changes: 43 additions & 1 deletion _sources/book/testing/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pytest"
"# Testing"
]
},
{
Expand Down Expand Up @@ -316,6 +316,48 @@
"source": [
"!pytest -v # -v for detailed but clean output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Property-based Testing with `hypothesis`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Looking for a smarter way to test your Python code?\n",
"\n",
"Use `hypothesis`.\n",
"\n",
"With `hypothesis`, you define properties your code should uphold, and it generates diverse test cases, uncovering edge cases and unexpected bugs.\n",
"\n",
"I encourage you to look into their documentation since it’s really upgrading your testing game."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install hypothesis"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from hypothesis import given, strategies as st\n",
"\n",
"@given(st.integers(), st.integers())\n",
"def test_addition_commutative(a, b):\n",
" assert a + b == b + a"
]
}
],
"metadata": {
Expand Down
52 changes: 51 additions & 1 deletion book/cooltools/Chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../testing/index.html">11. Testing in Python</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-11"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../testing/Chapter.html">11.1. Pytest</a></li>
<li class="toctree-l2"><a class="reference internal" href="../testing/Chapter.html">11.1. Testing</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../Miscellaneous/index.html">12. Miscellaneous</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-12"><i class="fa-solid fa-chevron-down"></i></label><ul>
Expand Down Expand Up @@ -434,6 +434,8 @@ <h2> Contents </h2>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#diagram-as-code-with-diagrams">2.1.26. Diagram-as-Code with <code class="docutils literal notranslate"><span class="pre">diagrams</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#powerful-retry-functionality-with-tenacity">2.1.27. Powerful Retry Functionality with <code class="docutils literal notranslate"><span class="pre">tenacity</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#performant-graph-analysis-with-python-igraph">2.1.28. Performant Graph Analysis with <code class="docutils literal notranslate"><span class="pre">python-igraph</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#speedtests-via-cli-with-speedtest-cli">2.1.29. Speedtests via CLI with <code class="docutils literal notranslate"><span class="pre">speedtest-cli</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#minimalistic-database-for-python-with-tinydb">2.1.30. Minimalistic Database for Python with <code class="docutils literal notranslate"><span class="pre">tinydb</span></code></a></li>
</ul>
</nav>
</div>
Expand Down Expand Up @@ -1266,6 +1268,52 @@ <h2><span class="section-number">2.1.28. </span>Performant Graph Analysis with <
</div>
</div>
</section>
<section id="speedtests-via-cli-with-speedtest-cli">
<h2><span class="section-number">2.1.29. </span>Speedtests via CLI with <code class="docutils literal notranslate"><span class="pre">speedtest-cli</span></code><a class="headerlink" href="#speedtests-via-cli-with-speedtest-cli" title="Permalink to this heading">#</a></h2>
<p>If you want to test your internet bandwidth via your CLI</p>
<p>try <code class="docutils literal notranslate"><span class="pre">speedtest-cli</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">speedtest-cli</span></code> tests your internet bandwidth via speedtest(dot)net.</p>
<p>It’s installable via pip.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>!pip install speedtest-cli
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>!speedtest-cli
</pre></div>
</div>
</div>
</div>
</section>
<section id="minimalistic-database-for-python-with-tinydb">
<h2><span class="section-number">2.1.30. </span>Minimalistic Database for Python with <code class="docutils literal notranslate"><span class="pre">tinydb</span></code><a class="headerlink" href="#minimalistic-database-for-python-with-tinydb" title="Permalink to this heading">#</a></h2>
<p>Do you search for a minimalistic document-oriented database in Python?</p>
<p>Use <code class="docutils literal notranslate"><span class="pre">tinydb</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">tinydb</span></code> is written in pure Python and offers a lightweight document-oriented database.</p>
<p>It’s perfect for small apps and hobby projects.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>!pip install tinydb
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tinydb</span> <span class="kn">import</span> <span class="n">TinyDB</span><span class="p">,</span> <span class="n">Query</span>

<span class="n">db</span> <span class="o">=</span> <span class="n">TinyDB</span><span class="p">(</span><span class="s1">&#39;/path/to/db.json&#39;</span><span class="p">)</span>
<span class="n">db</span><span class="o">.</span><span class="n">insert</span><span class="p">({</span><span class="s1">&#39;int&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;char&#39;</span><span class="p">:</span> <span class="s1">&#39;a&#39;</span><span class="p">})</span>
<span class="n">db</span><span class="o">.</span><span class="n">insert</span><span class="p">({</span><span class="s1">&#39;int&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;char&#39;</span><span class="p">:</span> <span class="s1">&#39;b&#39;</span><span class="p">})</span>
</pre></div>
</div>
</div>
</div>
</section>
</section>

<script type="text/x-thebe-config">
Expand Down Expand Up @@ -1357,6 +1405,8 @@ <h2><span class="section-number">2.1.28. </span>Performant Graph Analysis with <
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#diagram-as-code-with-diagrams">2.1.26. Diagram-as-Code with <code class="docutils literal notranslate"><span class="pre">diagrams</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#powerful-retry-functionality-with-tenacity">2.1.27. Powerful Retry Functionality with <code class="docutils literal notranslate"><span class="pre">tenacity</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#performant-graph-analysis-with-python-igraph">2.1.28. Performant Graph Analysis with <code class="docutils literal notranslate"><span class="pre">python-igraph</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#speedtests-via-cli-with-speedtest-cli">2.1.29. Speedtests via CLI with <code class="docutils literal notranslate"><span class="pre">speedtest-cli</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#minimalistic-database-for-python-with-tinydb">2.1.30. Minimalistic Database for Python with <code class="docutils literal notranslate"><span class="pre">tinydb</span></code></a></li>
</ul>
</nav></div>

Expand Down
2 changes: 1 addition & 1 deletion book/cooltools/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../testing/index.html">11. Testing in Python</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-11"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../testing/Chapter.html">11.1. Pytest</a></li>
<li class="toctree-l2"><a class="reference internal" href="../testing/Chapter.html">11.1. Testing</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../Miscellaneous/index.html">12. Miscellaneous</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-12"><i class="fa-solid fa-chevron-down"></i></label><ul>
Expand Down
Loading

0 comments on commit 4bba14a

Please sign in to comment.