Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the the Python package compatible with Athena PySpark #33

14 changes: 5 additions & 9 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ jobs:
needs: website

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: python/pyproject.toml
cache-suffix: docs
uses: astral-sh/setup-uv@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: python/pyproject.toml
shell: bash
working-directory: python
run: uv venv

- name: Install Python dependencies
working-directory: python
Expand All @@ -54,7 +50,7 @@ jobs:
shell: Rscript {0}

- name: Build Python docs
run: sphinx-build python/docs/source docs/python
run: uv run sphinx-build python/docs/source docs/python

- name: Configure pages
uses: actions/configure-pages@v5
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/pytest-coverage.yaml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/python-build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
pull_request:
push:
branches: [main, master]

name: python-build-and-test

env:
PYTHONUNBUFFERED: "1"

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: python/pyproject.toml
cache-suffix: ${{ matrix.python-version }}-test

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install tox
shell: bash
run: |
uv tool install tox --with tox-uv,tox-gh-actions
tox --version

- name: Build and test with tox
shell: bash
working-directory: python
run: tox r
13 changes: 7 additions & 6 deletions python/ccao/vars_funs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Functions for translating variables between different data sources
import importlib.resources
import typing

import pandas as pd

Expand All @@ -14,12 +15,12 @@


def vars_rename(
data: list[str] | pd.DataFrame,
data: typing.Union[typing.List[str], pd.DataFrame],
names_from: str,
names_to: str,
output_type: str = "inplace",
dictionary: pd.DataFrame | None = None,
) -> list[str] | pd.DataFrame:
dictionary: typing.Optional[pd.DataFrame] = None,
) -> typing.Union[typing.List[str], pd.DataFrame]:
"""
Rename variables from one naming convention to another.

Expand Down Expand Up @@ -130,10 +131,10 @@ def vars_rename(

def vars_recode(
data: pd.DataFrame,
cols: list[str] | None = None,
cols: typing.Optional[typing.List[str]] = None,
code_type: str = "long",
as_factor: bool = True,
dictionary: pd.DataFrame | None = None,
dictionary: typing.Optional[pd.DataFrame] = None,
) -> pd.DataFrame:
"""
Replace numerically coded variables with human-readable values.
Expand Down Expand Up @@ -249,7 +250,7 @@ def vars_recode(
# vars dict
def transform_column(
col: pd.Series, var_name: str, values_to: str, as_factor: bool
) -> pd.Series | pd.Categorical:
) -> typing.Union[pd.Series, pd.Categorical]:
if var_name in dict_long["var_name"].values:
var_rows = dict_long[dict_long["var_name"] == var_name]
# Get a dictionary mapping the possible codes to their values.
Expand Down
53 changes: 45 additions & 8 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ name = "ccao"
version = "1.3.0"
description = "Convenience Functions and Datasets for the Cook County Assessor's Office"
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.9"
authors = [
{name = "Jean Cochrane", email="jean.cochrane@cookcountyil.gov"},
{name = "Dan Snow", email="daniel.snow@cookcountyil.gov"},
]
dependencies = [
"pandas>=2.2.3",
"pandas>=1.4.3",
"numpy>=1.23.1"
]

[project.optional-dependencies]
dev = [
"mypy>=1.13.0",
"pytest>=8.3.3",
"ruff>=0.7.4",
"mypy>=1.0.0",
"pytest>=7.0.0",
"ruff>=0.8.0",
]
docs = [
"Sphinx>=8.1.3",
"myst-parser>=4.0.0",
"Sphinx>=7.0",
"myst-parser>=1.0.0",
"pydata-sphinx-theme>=0.16.0",
"sphinx-pyproject>=0.3.0"
"sphinx-pyproject>=0.3.0",
"sphinx-autobuild>=2024.10.3"
]

[tool.setuptools]
Expand Down Expand Up @@ -55,3 +57,38 @@ highlight_language = "none"
html_theme = "pydata_sphinx_theme"
html_logo = "../images/logo.png"
html_show_copyright = false

[tool.pytest.ini_options]
minversion = "7.0"
addopts = "-v --cache-clear -rf --doctest-modules"
console_output_style = "count"

[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
envlist =
py{39, 310, 311}-lowest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We end the lowest-direct tests at Python 3.11 since myst-parser didn't add support for 3.12 until 3.0.

py{39, 310, 311, 312, 313}

[gh-actions]
python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312
3.13: py313

[testenv]
extras = dev,docs
commands = pytest
passenv =
UV_CACHE_DIR
PYTHONUNBUFFERED

[testenv:py{39, 310, 311}-lowest]
uv_resolution = lowest-direct

[testenv:py{39, 310, 311, 312, 313}]
uv_resolution = highest
"""
Loading