Skip to content

pycensus.census.countries.mexico.inegi.loader

Loader for INEGI Census (Censo de Poblacion y Vivienda) 2020, returning a common-schema GeoDataFrame.

Technical aspects

Mirrors :mod:pycensus.usa.acs5.loader's shape: reads as much as possible from pyCensus' parquet cache (:mod:pycensus.cache), fetching only the logical columns actually missing, and merges the result back into the shared per-level/region cache file. The difference from every usa.* source is that INEGI has no queryable API -- :mod:pycensus.mexico.api downloads and caches INEGI's bulk per-state ITER CSV on disk (independent of, and upstream of, :mod:pycensus.cache's parquet cache) the first time any column is requested for a state, then every subsequent column/level request for that state is served from the already-downloaded file.

state, municipality, ageb (urban only), and block (urban only) levels are implemented. ageb/block-level attribute columns come from a different INEGI bulk file, RESAGEBURB (:func:pycensus.mexico.api.fetch_ageb_totals/ :func:pycensus.mexico.api.fetch_block_totals), not ITER (see :mod:pycensus.mexico.geography for the live end-to-end verification of the block boundary/attribute pairing).

Source

INEGI Census 2020: https://www.inegi.org.mx/programas/ccpv/2020/

load(aoi=None, states=None, level='municipality', year='latest', cache_dir=None, cache=True, data_dir=None)

Load INEGI Census 2020 data as a common-schema GeoDataFrame.

Parameters:

Name Type Description Default
aoi Optional[GeoDataFrame]

Area of interest. Used to auto-detect states if not given, and to clip the final result. Every state is checked since no national boundary layer is wired up to pre-filter (see :func:pycensus.mexico.geography.states_in_aoi).

None
states Optional[Union[str, List[str]]]

State name(s)/abbreviation(s)/code(s) to load. Derived from aoi if omitted (aoi is then required).

None
level str

Standard geometry level name. "state", "municipality", "ageb", and "block" are implemented; other standard levels (e.g. "tract"/"blockgroup") fall back onto one of those via :data:pycensus.mexico.constants.LEVEL_FALLBACK where possible, else raise.

'municipality'
year Union[int, str]

Vintage year, or "latest". Only 2020 is available.

'latest'
cache_dir Optional[str]

Root of pyCensus' parquet cache (geometry + attribute columns, merged per level/region). Defaults to :func:pycensus.cache.default_cache_dir.

None
cache bool

If False, bypass the parquet cache entirely -- always fetch fresh and don't persist the result. INEGI's own raw ITER/Marco Geoestadistico downloads (:mod:pycensus.mexico.api, :mod:pycensus.mexico.geography) are cached on disk independently of this flag, since re-downloading multi-MB per-state files on every call would be impractical.

True
data_dir Optional[str]

Base directory for INEGI's raw downloaded files (ITER CSVs, Marco Geoestadistico zips). Defaults to :data:pycensus.mexico.constants.DEFAULT_DATA_DIR.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with GEOID, geometry, and one inegi_-prefixed

GeoDataFrame

column per logical column in :data:pycensus.mexico.inegi.schema.SCHEMA.

Raises:

Type Description
ValueError

If neither states nor aoi is given, or level has no implemented data source.