pycensus.geometry_levels¶
Standard cross-country geometry level vocabulary and per-country fallback resolution.
Technical aspects
Every country module is expected to accept level values from this
same fixed vocabulary, regardless of whether that geography natively
exists there. A country declares a LEVEL_FALLBACK dict (e.g.
USA.constants.LEVEL_FALLBACK) mapping any level it lacks to the
closest one it does have (e.g. the US has no "province", so
"province" -> "county"); :func:resolve_level walks that mapping
until it lands on a level the country actually implements. This keeps
calling code (loaders, notebooks, cross-country comparisons) written
against one consistent set of level names.
STANDARD_LEVELS = ['block', 'blockgroup', 'tract', 'place', 'county', 'province', 'state', 'nation']
module-attribute
¶
Geometry levels every country census source should accept, finest to coarsest-ish.
resolve_level(level, fallback, country=None)
¶
Walk a country's fallback map until level names something it natively supports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Requested standard level name. |
required |
fallback
|
Dict[str, str]
|
Country-specific |
required |
country
|
Optional[str]
|
Optional country name, accepted for a clearer error message
and to match the call signature used consistently across every
country module's |
None
|
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
ultimately resolves to (following chained fallbacks, without looping |
str
|
forever on a cycle). |
is_native_level(native_levels, level)
¶
Whether a source genuinely publishes data at level itself.
Distinct from a schema's broader "levels" list (every geometry a
source's rows can be resolved/joined to, e.g. via TIGER boundaries),
which is NOT the same claim as "this source's own tabulated values are
published at this resolution" -- e.g. ACS5's "levels" used to
(incorrectly) include "block", a level ACS5 can never actually
publish estimates at (Census only tabulates ACS down to blockgroup).
native_levels (a schema JSON's own separate key, added 2026-09-29)
is the accurate list for exactly this question, and calling code
(loaders, resampling pipelines) should check it before resampling a
level a source already natively covers -- resampling should only ever
fill in a level that ISN'T in this list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_levels
|
List[str]
|
A source schema's |
required |
level
|
str
|
Standard level name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |