pycensus.census.countries.spain.ine.loader¶
Loader for Spain's INE Padron municipal, returning a common-schema GeoDataFrame.
Technical aspects
Mirrors :mod:pycensus.mexico.inegi.loader's shape: reads as much as
possible from pyCensus' parquet cache (:mod:pycensus.cache), fetching
only the logical columns actually missing. Unlike Mexico's per-state
ITER file, INE's Tempus API (:mod:pycensus.spain.api) returns every
Spanish municipality in a single request, so the raw response is
downloaded once (cached on disk, independent of the parquet cache) and
then sliced per requested region/level.
Only population/malePopulation/femalePopulation are
implemented -- see :mod:pycensus.spain.ine.schema module docstring
for why fields present in earlier (fabricated) versions of this module
(age brackets, employment, income, housing) were removed rather than
kept with invented INE codes: they were never verified against a real
downloaded INE file. Real values for those exist in INE's Census 2021
(Censo de Poblacion y Viviendas) microdata/tables, which is a separate,
unverified follow-up (see this module's download_census_data
docstring).
Source
INE Padron municipal (table 29005): https://servicios.ine.es/wstempus/js/ES/DATOS_TABLA/29005
load(aoi=None, regions=None, level='municipality', year='latest', api_key=None, cache_dir=None, cache=True, data_dir=None)
¶
Load INE's Padron municipal population data as a common-schema GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Optional[GeoDataFrame]
|
Area of interest. Used to auto-detect |
None
|
regions
|
Optional[Union[str, List[str]]]
|
Region code(s) -- autonomous community code, province code,
or 5-digit municipality code, matching |
None
|
level
|
str
|
Standard geometry level name. Spain supports |
'municipality'
|
year
|
Union[int, str]
|
Vintage year, or |
'latest'
|
api_key
|
Optional[str]
|
Not used -- INE's Padron Tempus API requires no API key. |
None
|
cache_dir
|
Optional[str]
|
Root of pyCensus' parquet cache. Defaults to
:func: |
None
|
cache
|
bool
|
If |
True
|
data_dir
|
Optional[str]
|
Root directory for raw INE/GISCO downloads (separate from
|
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with |
GeoDataFrame
|
column per logical column in :data: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
NotImplementedError
|
If |
download_census_data(level='municipality', regions=None, data_dir=None, overwrite=False)
¶
Force a fresh download of INE's Padron municipal table to the raw cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Accepted for interface parity; the Padron API returns every municipality in one request regardless of level. |
'municipality'
|
regions
|
Optional[Union[str, List[str]]]
|
Accepted for interface parity; not used to filter the download (the raw file always holds every municipality). |
None
|
data_dir
|
Optional[str]
|
Root directory for raw downloads. |
None
|
overwrite
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the raw cache file that was downloaded/refreshed. |
Note
Only the Padron (population by sex) is implemented here. INE's Census 2021 (Censo de Poblacion y Viviendas) publishes households, housing, education, and employment data at municipality level too, via the same Tempus API under a different operation/table id, but that was not identified and verified against a real downloaded file in this rebuild -- see the module docstring.