Skip to content

Commit

Permalink
Merge pull request #4 from PovertyAction/set-up-gh-actions
Browse files Browse the repository at this point in the history
Set up gh actions
  • Loading branch information
NKeleher authored Jun 11, 2024
2 parents 3e48558 + 98957dc commit 5c49aba
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
workflow_dispatch:
push:
branches: main
pull_request:
branches: main

name: Publish Quarto Site
#docs: https://github.com/quarto-dev/quarto-actions/blob/main/examples/quarto-publish-example.yml
#docs: https://github.com/marketplace/actions/python-setup-rye

jobs:
build-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
python-version: ["3.12.3"]
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2

- name: Set up Rye
id: setup-rye
uses: eifinger/setup-rye@v3
with:
enable-cache: false

- name: Pin python version ${{ matrix.python-version }}
if: steps.setup-rye.outputs.cache-hit != 'true'
run: rye pin ${{ matrix.python-version }}

- name: Install dependencies
if: steps.setup-rye.outputs.cache-hit != 'true'
run: |
rye sync
# From https://github.com/r-lib/actions/tree/v2-branch/setup-r
# - name: Setup R
# uses: r-lib/actions/setup-r@v2

- name: Render and Publish
uses: quarto-dev/quarto-actions/publish@v2
with:
target: gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions _freeze/docs/software/python/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"hash": "4b63122f49e879066f27419fa2410bbd",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: Python\nexecute:\n eval: true\n---\n\n## What is Python?\n\nPython is a high-level, general-purpose programming language that is widely used in data\nscience, machine learning, and web development. It has a large standard library and a\nvibrant community that provides a wide range of libraries and tools for various\napplications. As such, Python provides a general-purpose ecosystem that can be used for\na wide range of applications.\n\n## How to install Python?\n\nThere are many ways to install Python. We recommend using Python in a virtual\nenvironment to avoid conflicts with other Python installations on your system.\n\nWe recommend using a [rye](https://rye.astral.sh/) or [pixi](https://pixi.sh/latest/).\nBoth of these tools provide a simple way to create and manage Python virtual\nenvironments.\n\nIn both cases, you can manage the python packages that are installed in the virtual\nenvironment using a `pyproject.toml` file. See the pyproject.toml example in this\nrepository for an example of how to manage Python packages. To add package dependencies\nto the virtual environment, using `rye`, you can run:\n\nWe'll use `rye` to demonstrate how to manage a Python virtual environment. Watch the\nfollowing video for a quick introduction to `rye`:\n\n\n{{< video https://youtu.be/q99TYA7LnuA >}}\n\n\n\nFirst, install `rye` using `winget` (Windows) or `brew` (MacOS/Linux):\n\n| Platform | Commands |\n| -------- | -------------------- |\n| Windows | `winget install rye` |\n| MacOS | `brew install rye` |\n| Linux | `brew install rye` |\n\nAdd libraries to the virtual environment using `rye add ...`:\n\n::: {#17aaecd9 .cell execution_count=1}\n``` {.python .cell-code}\n> rye add jupyterlab pandas matplotlib seaborn\n```\n:::\n\n\n## Coding Conventions\n\nSee the\n[GitLab Data Team's Python Guide](https://handbook.gitlab.com/handbook/business-technology/data-team/platform/python-guide/)\n\n## Learning Resources\n\nDownload data from the a URL:\n\n::: {#3cb20ef0 .cell execution_count=2}\n``` {.python .cell-code}\nfrom urllib.request import urlretrieve\n\n_ = urlretrieve(\n \"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv\",\n \"../assets/data/penguins.csv\",\n)\n```\n:::\n\n\n::: {#c593971b .cell execution_count=3}\n``` {.python .cell-code}\nimport pandas as pd\n\ndf = pd.read_csv(\"../assets/data/penguins.csv\")\n```\n:::\n\n\n::: {#a5d84efe .cell execution_count=4}\n``` {.python .cell-code}\nimport matplotlib.pyplot as plt # noqa: E402\nimport seaborn as sns # noqa: E402\n\ng = sns.FacetGrid(df, hue=\"species\", height=3, aspect=1.5)\ng.map(plt.scatter, \"bill_length_mm\", \"bill_depth_mm\").add_legend()\n```\n\n::: {.cell-output .cell-output-display}\n![](python_files/figure-html/cell-5-output-1.png){width=527 height=278}\n:::\n:::\n\n\n## Learning Resources\n\n- [The Python Tutorial](https://docs.python.org/3.12/tutorial/index.html)\n- [Python Data Science Handbook](https://jakevdp.github.io/PythonDataScienceHandbook/)\n- [Efficient Python for Data Scientists](https://khuyentran1401.github.io/Efficient_Python_tricks_and_tools_for_data_scientists/README.html)\n- [The Hitchhiker's Guide to Python](https://docs.python-guide.org/)\n\n",
"supporting": [
"python_files"
],
"filters": [],
"includes": {}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions _freeze/docs/software/sql/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "887ca8660e522965857be1e3935466ab",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: SQL\n---\n\n## What is SQL?\n\nSQL (pronounced \"sequel\") stands for Structured Query Language. It is a standard\nlanguage for accessing and manipulating databases. SQL is used to organize data in a\ndatabase as well as as questions of that data.\n\nThe traditional use of SQL is in relational databases, but it can also be used in other\ntypes of databases. In the examples below, we use [duckdb](https://duckdb.org/) which\nhas become a leading option for analytical workflows across a diverse set of data\nstorage types (e.g. relational databases, csv, parquet, json, etc.).\n\n## How to install SQL?\n\nTo use DuckDB, you can add it to your python virtual environment using `rye`:\n\n```{.bash}\nrye add duckdb duckdb-engine\n```\n\n## Using SQL\n\nConnect to a database.\n\n::: {#a9519b24 .cell execution_count=1}\n``` {.python .cell-code}\n%load_ext sql\n%sql duckdb://\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nC:\\Users\\NKeleher\\code\\ipa-data-tech-handbook\\.venv\\Lib\\site-packages\\sql\\parse.py:320: SyntaxWarning: invalid escape sequence '\\:'\n \"\"\"\nC:\\Users\\NKeleher\\code\\ipa-data-tech-handbook\\.venv\\Lib\\site-packages\\sql\\parse.py:350: SyntaxWarning: invalid escape sequence '\\:'\n \"\"\"\n```\n:::\n\n::: {.cell-output .cell-output-display}\n```{=html}\n<span style=\"None\">Loading configurations from C:\\Users\\NKeleher\\code\\ipa-data-tech-handbook\\pyproject.toml.</span>\n```\n:::\n\n::: {.cell-output .cell-output-display}\n```{=html}\n<span style=\"None\">Settings changed:</span>\n```\n:::\n\n::: {.cell-output .cell-output-display}\n```{=html}\n\n<table>\n <thead>\n <tr>\n <th>Config</th>\n <th>value</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>feedback</td>\n <td>0</td>\n </tr>\n <tr>\n <td>autopandas</td>\n <td>False</td>\n </tr>\n <tr>\n <td>autopolars</td>\n <td>False</td>\n </tr>\n <tr>\n <td>autolimit</td>\n <td>0</td>\n </tr>\n <tr>\n <td>displaylimit</td>\n <td>10</td>\n </tr>\n </tbody>\n</table>\n```\n:::\n:::\n\n\nCreate a table from a CSV file.\n\n::: {#9c51d172 .cell execution_count=2}\n``` {.python .cell-code}\n%%sql\nCREATE TABLE penguins AS SELECT * FROM '../assets/data/penguins.csv'\n```\n\n::: {.cell-output .cell-output-display execution_count=2}\n```{=html}\n<table>\n <thead>\n <tr>\n <th>Count</th>\n </tr>\n </thead>\n <tbody>\n </tbody>\n</table>\n```\n:::\n:::\n\n\nInspect the columns of the table.\n\n::: {#9f6d4e3d .cell execution_count=3}\n``` {.python .cell-code}\n%sqlcmd columns -t penguins\n```\n\n::: {.cell-output .cell-output-display execution_count=3}\n```{=html}\n<table>\n <thead>\n <tr>\n <th>name</th>\n <th>type</th>\n <th>nullable</th>\n <th>default</th>\n <th>autoincrement</th>\n <th>comment</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>species</td>\n <td>VARCHAR</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>island</td>\n <td>VARCHAR</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>bill_length_mm</td>\n <td>FLOAT</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>bill_depth_mm</td>\n <td>FLOAT</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>flipper_length_mm</td>\n <td>BIGINT</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>body_mass_g</td>\n <td>BIGINT</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n <tr>\n <td>sex</td>\n <td>VARCHAR</td>\n <td>True</td>\n <td>None</td>\n <td>False</td>\n <td>None</td>\n </tr>\n </tbody>\n</table>\n```\n:::\n:::\n\n\nQuery the table using a `SELECT` statement.\n\n::: {#e7557271 .cell execution_count=4}\n``` {.python .cell-code}\n%%sql\nSELECT *\nFROM '../assets/data/penguins.csv'\nLIMIT 3\n```\n\n::: {.cell-output .cell-output-display execution_count=4}\n```{=html}\n<table>\n <thead>\n <tr>\n <th>species</th>\n <th>island</th>\n <th>bill_length_mm</th>\n <th>bill_depth_mm</th>\n <th>flipper_length_mm</th>\n <th>body_mass_g</th>\n <th>sex</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>Adelie</td>\n <td>Torgersen</td>\n <td>39.1</td>\n <td>18.7</td>\n <td>181</td>\n <td>3750</td>\n <td>MALE</td>\n </tr>\n <tr>\n <td>Adelie</td>\n <td>Torgersen</td>\n <td>39.5</td>\n <td>17.4</td>\n <td>186</td>\n <td>3800</td>\n <td>FEMALE</td>\n </tr>\n <tr>\n <td>Adelie</td>\n <td>Torgersen</td>\n <td>40.3</td>\n <td>18.0</td>\n <td>195</td>\n <td>3250</td>\n <td>FEMALE</td>\n </tr>\n </tbody>\n</table>\n```\n:::\n:::\n\n\nRun analytical operations on the data.\n\n::: {#2fcb8a5f .cell execution_count=5}\n``` {.python .cell-code}\n%%sql\nSELECT species, COUNT(*) AS count\nFROM '../assets/data/penguins.csv'\nGROUP BY species\nORDER BY count DESC\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```{=html}\n<table>\n <thead>\n <tr>\n <th>species</th>\n <th>count</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>Adelie</td>\n <td>152</td>\n </tr>\n <tr>\n <td>Gentoo</td>\n <td>124</td>\n </tr>\n <tr>\n <td>Chinstrap</td>\n <td>68</td>\n </tr>\n </tbody>\n</table>\n```\n:::\n:::\n\n\nUsing `jupysql` store SQL query results as an object in a Jupyter notebook.\n\n::: {#be06df78 .cell execution_count=6}\n``` {.python .cell-code}\n%%sql species_count <<\nSELECT species, COUNT(*) AS count\nFROM '../assets/data/penguins.csv'\nGROUP BY species\nORDER BY count DESC\n```\n:::\n\n\nPlot the results of the query.\n\n::: {#1dc4b5d7 .cell execution_count=7}\n``` {.python .cell-code}\nax = %sqlplot bar --table '../assets/data/penguins.csv' --column species\n\n# customize plot (this is a matplotlib Axes object)\n_ = ax.set_title(\"Count of penguins by species\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n<span style=\"None\">Removing NULLs, if there exists any from species</span>\n```\n:::\n\n::: {.cell-output .cell-output-display}\n![](sql_files/figure-html/cell-8-output-2.png){width=593 height=449}\n:::\n:::\n\n\n## Coding Conventions\n\nUse [SQLFluff](https://docs.sqlfluff.com/en/stable/) to lint SQL code.\n\nAdd SQLFluff to your virtual environment using `rye`:\n\n```{.bash}\nrye add sqlfluff\n```\n\nAssuming SQLFluff is installed in your virtual environment using `rye`, you can run the\nfollowing command to lint SQL code:\n\n```{.bash}\nrye run sqlfluff fix --dialect duckdb\n```\n\nSee the\n[GitLab Data Team's SQL Style Guide](https://handbook.gitlab.com/handbook/business-technology/data-team/platform/sql-style-guide/)\n\n## Learning Resources\n\n- [SELECT Star SQL](https://selectstarsql.com/)\n- [SQL Murder Mystery](https://mystery.knightlab.com/walkthrough.html)\n- [sql-workbench](https://sql-workbench.com/)\n- [DuckDB SQL Introduction](https://duckdb.org/docs/sql/introduction)\n\n",
"supporting": [
"sql_files"
],
"filters": [],
"includes": {
"include-in-header": [
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\" integrity=\"sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==\" crossorigin=\"anonymous\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js\" integrity=\"sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==\" crossorigin=\"anonymous\" data-relocate-top=\"true\"></script>\n<script type=\"application/javascript\">define('jquery', [],function() {return window.jQuery;})</script>\n"
]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5c49aba

Please sign in to comment.