You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(spatial): Replace custom TIGER/Line downloads with pygris (#308)
* feat(spatial): Replace custom TIGER/Line downloads with pygris
Use pygris for all shapefile downloads instead of manually constructing
Census Bureau URLs. This adds automatic caching, better year/vintage
handling, and fixes broken ZCTA/PUMA downloads for pre-2020 years.
- Replace _GEO_TO_TIGER URL templates with _GEO_TO_PYGRIS function dispatch
- Add GEOID column normalization for vintage variants (GEOID20, GEOID10)
- Add CRS assertion to guarantee EPSG:4269
- Enable pygris caching by default
- Add pygris>=0.1.7 to spatial optional deps
- Update docs to mention pygris and automatic caching
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(spatial): Address PR review feedback
- Remove AFFGEOID from GEOID normalization candidates (different format
would silently break merges)
- Only pass resolution kwarg to pygris functions that accept it (tracts,
block_groups, places, zctas, pumas do not)
- Add helpful ImportError when pygris function is missing
- Add cache parameter to _fetch_tiger_shapes and attach_geometry so
users can force fresh downloads
- Cap pygris version to <1 to guard against breaking API changes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(spatial): Address remaining review nits
- Include minimum version (>=0.1.7) in pygris ImportError message
- Add requires_state validation so tract/block group/place/puma raise
a clear ValueError when state is missing, instead of a cryptic pygris
error downstream
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: Update all references from TIGER/Line to pygris
Comprehensive docs sweep across 13 files:
- Replace "TIGER/Line" with "cartographic boundary" or "via pygris"
in all guides, migration docs, and getting-started pages
- Add 0.3 and 0.3.1 changelog entries with full details
- Update installation docs to mention pygris as spatial dependency
- Add cache=True to attach_geometry() signature in spatial guide
- Add ValueError troubleshooting entry for missing state param
- Update caching guide: remove stale geography/ dir, add pygris
cache section with OS-specific paths
- Fix example version number (0.2 -> 0.3) in installation.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/getting-started/installation.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ If you plan to work with shapefiles, choropleths, or any geometry (the `geometry
30
30
uv add "pypums[spatial]"
31
31
```
32
32
33
-
This adds [`geopandas`](https://geopandas.org/) and its dependencies (`shapely`, `pyproj`, `fiona`), which enable PyPUMS to fetch TIGER/Line shapefiles and return `GeoDataFrame` objects.
33
+
This adds [`geopandas`](https://geopandas.org/) and [`pygris`](https://github.com/walkerke/pygris) (plus their dependencies), enabling `geometry=True` to return `GeoDataFrame` objects. pygris handles shapefile downloads with automatic local caching — files are only downloaded once.
34
34
35
35
## Get a Census API key
36
36
@@ -124,7 +124,7 @@ Run this in your terminal to confirm PyPUMS is installed:
2.**variables** -- `B17001_002` is the count of people whose income is below the poverty level (from table B17001).
92
92
3.**state** -- Required for tract-level queries so the API knows which state to pull tracts from.
93
93
4.**county** -- `"037"` is the FIPS code for Los Angeles County. Use `pypums.datasets.fips.lookup_fips(state="California", county="Los Angeles County")` to look up codes.
94
-
5.**geometry** -- When `True`, PyPUMS fetches TIGER/Line cartographic boundary shapefiles and merges them with the data. The result is a `GeoDataFrame` with a `geometry` column.
94
+
5.**geometry** -- When `True`, PyPUMS downloads cartographic boundary shapefiles (via pygris, cached locally) and merges them with the data. The result is a `GeoDataFrame` with a `geometry` column.
95
95
96
96
Now plot it with [Altair](https://altair-viz.github.io/):
97
97
@@ -211,11 +211,13 @@ The resulting map shows poverty counts by Census tract across Los Angeles County
211
211
}
212
212
```
213
213
214
-
!!! info "What is a TIGER/Line shapefile?"
214
+
!!! info "How does `geometry=True` work?"
215
215
The Census Bureau publishes free geographic boundary files called
216
-
TIGER/Line shapefiles. When you set `geometry=True`, PyPUMS automatically
217
-
downloads the correct shapefile for your geography level and year, then
218
-
joins it to your data on the `GEOID` column.
216
+
TIGER/Line shapefiles. When you set `geometry=True`, PyPUMS uses
217
+
[pygris](https://github.com/walkerke/pygris) to download the correct
218
+
shapefile for your geography level and year, then joins it to your data
219
+
on the `GEOID` column. Files are cached locally so subsequent calls are
220
+
fast.
219
221
220
222
**What to try next:**[Spatial Data & Mapping guide](../guides/spatial.md) for dot-density maps, population-weighted interpolation, and custom resolutions.
0 commit comments