From 08853c4b9c209b268e7513ac0127c5c3486f0d79 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:19:58 +0000 Subject: [PATCH] Sort constituency weights (#46) * Constituency weights are not in sorted-name order Fixes #45 * Versioning * Fix minor bug --- CHANGELOG.md | 7 +++++++ changelog.yaml | 5 +++++ .../datasets/frs/local_areas/constituencies/calibrate.py | 3 ++- pyproject.toml | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a67552..468da82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.9.2] - 2024-11-30 13:23:17 + +### Fixed + +- Constituency weights are in A-Z order. + ## [1.9.1] - 2024-11-27 19:28:29 ### Added @@ -97,6 +103,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +[1.9.2]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.9.1...1.9.2 [1.9.1]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.9.0...1.9.1 [1.9.0]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.8.0...1.9.0 [1.8.0]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.7.0...1.8.0 diff --git a/changelog.yaml b/changelog.yaml index 6459818..c33312f 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -80,3 +80,8 @@ added: - Automatic calibration. date: 2024-11-27 19:28:29 +- bump: patch + changes: + fixed: + - Constituency weights are in A-Z order. + date: 2024-11-30 13:23:17 diff --git a/policyengine_uk_data/datasets/frs/local_areas/constituencies/calibrate.py b/policyengine_uk_data/datasets/frs/local_areas/constituencies/calibrate.py index 5d68c90..9926256 100644 --- a/policyengine_uk_data/datasets/frs/local_areas/constituencies/calibrate.py +++ b/policyengine_uk_data/datasets/frs/local_areas/constituencies/calibrate.py @@ -84,7 +84,8 @@ def loss(w): def update_weights(weights, mapping_matrix): mapping_matrix = mapping_matrix.set_index(mapping_matrix.columns[0]) mapping_matrix = mapping_matrix.div(mapping_matrix.sum(), axis=1) - return mapping_matrix.T.dot(weights) + mapped_weights = mapping_matrix.T.dot(weights).values + return mapped_weights[mapping_matrix.columns.argsort(), :] if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index bc018b7..8fd95ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "policyengine_uk_data" -version = "1.9.1" +version = "1.9.2" description = "A package to create representative microdata for the UK." readme = "README.md" authors = [