Skip to content

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 {unsupported_level: substitute_level} map.

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 geography.py/loader.py; not otherwise used by the resolution logic itself.

None

Returns:

Type Description
str

level itself if not in fallback, otherwise the level it

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 native_levels list (e.g. loaded from its *_schema.json).

required
level str

Standard level name to check.

required

Returns:

Type Description
bool

True if level is one of native_levels.