pycensus.census.countries.canada.utils¶
Small stateless helpers shared by every Canada census source module.
Technical aspects
Region-code resolution itself lives on
:mod:pycensus.canada.constants (province_code/province_abbr)
since Canada's code tables are small and it avoids an import cycle
with :mod:pycensus.canada.geography; this module re-exports them
(mirroring where pycensus.mexico.geography/pycensus.mexico.inegi.loader
reach for pycensus.mexico.utils.state_code) plus small
format-agnostic helpers used by more than one source.
province_abbr(province)
¶
Normalize a province name, abbreviation, or PRUID to its postal abbreviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
province
|
str
|
Province name, abbreviation or PRUID. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Postal abbreviation. |
province_code(province)
¶
Normalize a province name, postal abbreviation, or PRUID to its 2-digit PRUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
province
|
str
|
Province name, postal abbreviation, or 2-digit code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Two-digit StatCan PRUID. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
pick_geoid_column(columns)
¶
Pick the most specific GEOID-like column present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Candidate column names. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The best-matching column name, or |
Optional[str]
|
GEOID column. |