Small fixes
This commit is contained in:
parent
54fbcb1ea6
commit
083f8a982e
24 changed files with 1505 additions and 79 deletions
|
|
@ -52,6 +52,13 @@ JUMP_MIN_PRICE = 2_000_000
|
|||
MIN_BUILD_YEAR = 1700
|
||||
MAX_BUILD_YEAR = 2030
|
||||
|
||||
# Open-ended "before YYYY" bands (EPC only emits "before 1900") have no lower
|
||||
# bound. Rather than dropping these mostly Victorian-and-older dwellings, we
|
||||
# publish a representative year this many years under the stated upper bound
|
||||
# ("before 1900" -> 1890) so they still carry a build year and survive an
|
||||
# age-range filter; is_construction_date_approximate flags it as an estimate.
|
||||
OPEN_BAND_YEARS_BEFORE_BOUND = 10
|
||||
|
||||
# Plausibility bounds for raw EPC dimensions. EPC lodgements contain data-entry
|
||||
# errors (0 m storey heights, 116 m "interior height", 9,210 m² floor areas, 99
|
||||
# habitable rooms) that otherwise propagate verbatim into the published per-
|
||||
|
|
@ -68,10 +75,13 @@ def epc_band_to_year(band: pl.Expr) -> pl.Expr:
|
|||
|
||||
EPC age bands are ranges (e.g. ``1950-1966``); we use the band MIDPOINT
|
||||
(1958) rather than the lower bound, which previously biased every band-derived
|
||||
year ~10-15 years too young. Open-ended lower bands (``before 1900``) are too
|
||||
wide to pin to a year and return null. Single-year / ``... onwards`` bands use
|
||||
that year. Already-numeric inputs (a year produced by an earlier call) pass
|
||||
through unchanged. Years outside [MIN_BUILD_YEAR, MAX_BUILD_YEAR] are nulled.
|
||||
year ~10-15 years too young. Open-ended lower bands (``before 1900``) have no
|
||||
lower bound, so we publish a representative year OPEN_BAND_YEARS_BEFORE_BOUND
|
||||
years under the stated upper bound (``before 1900`` -> 1890) rather than
|
||||
dropping the dwelling; is_construction_date_approximate flags it as an
|
||||
estimate. Single-year / ``... onwards`` bands use that year. Already-numeric
|
||||
inputs (a year produced by an earlier call) pass through unchanged. Years
|
||||
outside [MIN_BUILD_YEAR, MAX_BUILD_YEAR] are nulled.
|
||||
"""
|
||||
text = (
|
||||
band.cast(pl.Utf8)
|
||||
|
|
@ -82,7 +92,7 @@ def epc_band_to_year(band: pl.Expr) -> pl.Expr:
|
|||
high = text.str.extract(r"(\d{4})\D+(\d{4})", 2).cast(pl.Int32, strict=False)
|
||||
year = (
|
||||
pl.when(text.str.starts_with("before "))
|
||||
.then(None)
|
||||
.then(low - OPEN_BAND_YEARS_BEFORE_BOUND)
|
||||
.when(high.is_not_null())
|
||||
.then(((low + high) / 2).round(0).cast(pl.Int32))
|
||||
.otherwise(low)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue