Skip to content

Commit

Permalink
Setup mypy and fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsnow committed Oct 31, 2024
1 parent eb33b0d commit af3ae4c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ repos:
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies: [
"pandas-stubs>=2.2.3.241009",
"types-PyYAML>=6.0.12.20240917",
"types-requests>=2.32.0.20241016"
]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.29.0
hooks:
Expand Down
4 changes: 2 additions & 2 deletions data/src/calculate_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def create_write_path(key: str, out_type: str, output_dict: dict) -> str:

origins = (
pd.read_parquet(input["files"]["origins_file"])
.loc[:, od_cols.keys()]
.loc[:, list(od_cols.keys())]
.rename(columns=od_cols)
.sort_values(by="id")
)
Expand All @@ -333,7 +333,7 @@ def create_write_path(key: str, out_type: str, output_dict: dict) -> str:

destinations = (
pd.read_parquet(input["files"]["destinations_file"])
.loc[:, od_cols.keys()]
.loc[:, list(od_cols.keys())]
.rename(columns=od_cols)
.sort_values(by="id")
)
Expand Down
Empty file added data/src/utils/__init__.py
Empty file.
9 changes: 6 additions & 3 deletions data/src/utils/census.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ def weighted_mean(
return group[value_col].mean()
return (group[value_col] * group[weight_col]).sum() / total_weight

def calculate_group_weighted_means(group: pd.DataFrame) -> pd.Series:
return pd.Series(
{col: weighted_mean(group, weight_col, col) for col in value_cols}
)

grouped = df.groupby(group_cols)
weighted_means = grouped.apply(
lambda x: pd.Series(
{col: weighted_mean(x, weight_col, col) for col in value_cols}
)
calculate_group_weighted_means
).reset_index()

return weighted_means
Expand Down
23 changes: 6 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ site = [
"pyyaml==6.0.2",
"requests==2.32.3"
]
test = [
dev = [
"setuptools>=61.0",
"pandas-stubs>=2.2.3.241009",
"pre-commit>=4.0.1",
"pytest>=7.3.0",
"pytest-cov>=4.1.0",
"types-PyYAML>=6.0.12.20240917",
"types-requests>=2.32.0.20241016"
]

[build-system]
requires = ["setuptools >= 61.0"]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
Expand All @@ -71,18 +75,3 @@ line-length = 79

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
envlist = py39, py38, py310, py311, py312
[gh]
python =
3.12 = py312
3.11 = py311
3.10 = py310
3.9 = py39
3.8 = py38
"""

0 comments on commit af3ae4c

Please sign in to comment.