Skip to content

Commit 29fc538

Browse files
chekosclaude
andauthored
Add Phase 3: estimates, flows, FIPS lookups, and caching integration (#297)
* Add Phase 3: estimates, flows, variable caching, FIPS lookups, and API caching - Create pypums/estimates.py with get_estimates() for Population Estimates Program data - Create pypums/flows.py with get_flows() for ACS Migration Flows data - Enhance load_variables() with persistent disk caching via CensusCache - Add lookup_fips() and lookup_name() to pypums/datasets/fips.py - Wire cache_table=True option into get_acs(), get_decennial(), get_pums() - Export get_estimates, get_flows, lookup_fips, lookup_name from package Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix review issues: cache key collisions, pickle→parquet, input validation - Fix cache key collisions: include output, moe_level, summary_var, pop_group, rep_weights, recode, variables_filter, puma in cache keys - Switch cache.py from pickle to parquet to eliminate arbitrary code execution risk from tampered cache files - Add pyarrow dependency (required for parquet serialization) - Validate product parameter in get_estimates() — raise ValueError for unknown products instead of silent fallback - Validate geography parameter in get_flows() against allowed values - Add cache_table parameter to get_estimates() and get_flows() for consistent API surface - Document unimplemented parameters (time_series, breakdown_labels, output, moe_level) in docstrings - Fix double _get_persistent_cache() instantiation in variables.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix cache_table to read from cache before API call in estimates/flows The cache_table parameter was write-only — it stored results but never checked for cached data before making API calls. Also adds variables, breakdown, and year to cache keys to prevent collisions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add pre-commit hooks with Ruff linting and formatting Set up .pre-commit-config.yaml with ruff-check, ruff-format, and standard pre-commit hooks (trailing whitespace, end-of-file, yaml/toml checks). Fix all lint errors across the codebase: line length, import ordering, formatting, zip() strict parameter, and trailing whitespace. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Reuse single CensusCache instance per cached call Instantiate CensusCache once before the cache read check and reuse the same instance for the write, instead of creating two separate instances. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0d3500e commit 29fc538

33 files changed

+694
-105
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@
2424
- [ ] I've read the [`CODE_OF_CONDUCT.md`](https://github.com/chekos/pypums/blob/master/CODE_OF_CONDUCT.md) document.
2525
- [ ] I've read the [`CONTRIBUTING.md`](https://github.com/chekos/pypums/blob/master/CONTRIBUTING.md) guide.
2626
- [ ] I've written tests for all new methods and classes that I created.
27-

.github/workflows/claude.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ jobs:
4747
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
4848
# or https://code.claude.com/docs/en/cli-reference for available options
4949
# claude_args: '--allowed-tools Bash(gh pr:*)'
50-

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repos:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: check-yaml
8+
args: [--unsafe]
89
- id: check-toml
910
- id: check-added-large-files
1011
- repo: https://github.com/astral-sh/ruff-pre-commit

docs/about/contributing.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ local development.
7373
Or if you are using `pipenv`:
7474

7575
pipenv shell
76-
76+
7777
Now install the dependencies and test dependencies:
7878

7979
pip install -e '.[test]'
@@ -82,7 +82,7 @@ local development.
8282

8383
git checkout -b name-of-your-bugfix-or-feature
8484

85-
Now you can make your changes locally.
85+
Now you can make your changes locally.
8686
<br>
8787

8888
5. When you're done making changes, check that your changes pass
@@ -111,4 +111,3 @@ Before you submit a pull request, check that it meets these guidelines:
111111
3. The pull request should work for Python 3.6 - 3.9.
112112
Check <https://travis-ci.org/chekos/pypums/pull_requests>
113113
and make sure that the tests pass for all supported Python versions.
114-

docs/about/history.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
- Bug fixes (some url's at the census website didn't have `content-size`, switched to default dict to move past that case)
1111

1212
## 0.0.5 (2019-05-11)
13-
- Add `.as_dataframe()` to ACS class.
13+
- Add `.as_dataframe()` to ACS class.
1414

1515
## 0.0.4 (2019-05-10)
16-
- Add `.download_data()` to ACS class.
16+
- Add `.download_data()` to ACS class.
1717

1818
## 0.0.3 (2019-05-09)
1919
- Accidentally released lol

docs/css/custom.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ div.autodoc-docstring {
33
margin-bottom: 30px;
44
border-left: 5px solid rgba(230, 230, 230);
55
}
6-
6+
77
div.autodoc-members {
88
padding-left: 20px;
99
margin-bottom: 15px;
10-
}
10+
}

docs/reference/surveys.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
members:
66
- download
77
- as_dataframe
8-

docs/user-guide/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can use `pypums` as a CLI on your terminal or in your scripts or notebooks.
44

55
## As a CLI
66

7-
On your terminal `pypums --help` or `pypums --version` to make sure it's installed
7+
On your terminal `pypums --help` or `pypums --version` to make sure it's installed
88

99
```shell
1010
pypums --version
@@ -40,7 +40,7 @@ Options:
4040
```
4141

4242
### `pypums download-acs`
43-
You can use the `download-acs` command to download the zip file containing the data for the specified ACS. It will extract it by default.
43+
You can use the `download-acs` command to download the zip file containing the data for the specified ACS. It will extract it by default.
4444

4545
This command requires at least the `year` and `state` of the survey to download.
4646

@@ -98,4 +98,4 @@ ca_2023.download(data_directory="./data/")
9898

9999
# to use it as a dataframe
100100
ca_2023_df = ca_2023.as_dataframe()
101-
```
101+
```

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nav:
66
- User guide:
77
- Installation: user-guide/installation.md
88
- Usage: user-guide/usage.md
9-
- API reference:
9+
- API reference:
1010
- Surveys (ACS): reference/surveys.md
1111
- CLI: reference/cli.md
1212
- About:
@@ -24,7 +24,7 @@ plugins:
2424
options:
2525
show_source: false
2626
show_root_heading: true
27-
27+
2828
markdown_extensions:
2929
- smarty
3030
- toc:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"us>=2.0.2",
1515
"httpx>=0.22.0",
1616
"pandas>=1.1.0",
17+
"pyarrow>=10.0.0",
1718
"rich>=11.0.0",
1819
"typer>=0.4.0",
1920
]

0 commit comments

Comments
 (0)