Repository navigation
feat(analyses): police recorded crime as needs, counted in offences - #237
Merged
Merged
Conversation
A new loader, uk_open_data.crime.load_crime(), reads the latest quarter's police recorded crime for every community safety partnership in England and Wales. The source is ONS's "Crime in England and Wales: Police Force Area data tables", where the figures by partnership moved when ONS discontinued their own dataset in 2024. - It finds the latest edition through the JSON the ONS website gives for each page. - It returns one row per partnership, with one column per kind of offence. - Each force's total and its "Unassigned" offences are left out. - A partnership whose row ONS marks with a note has missing figures, not the published few. ONS marks five Kent partnerships so today, because their crimes are recorded under "Unassigned Kent". Need against reach, provision gap and access and distance can now take two needs, for England and Wales, as agreed on 1 December: - recorded_crime: offences excluding fraud; - violence_against_the_person. They count offences, so results say "offences recorded", and the caveat says offences are not people or victims. The figures are for partnerships, so they are shared out to councils by residents (#218). Most partnerships are one council. A council whose partnership has no figure is left out and named. The working's sentence on sharing now rounds to whole units of what the need counts, such as offences or children, not "whole people". The datasets test keeps each need's invented figures by the need's own kind of area. Signed-off-by: billlyzhaoyh <billlyzhaoyh@users.noreply.github.com> Github-Issue: #210
After review: - The loader left out any partnership marked with a note. A note only says something applies; ONS's partnership notes also cover small numbers and undercounts. It now reads the "Notes - CSP" sheet and leaves out a partnership's figures only when its note says its offences are recorded as "Unassigned", as note 5 does of five Kent partnerships today. A note about anything else, such as Northumbria's robbery undercount in 2025, leaves the figures as they are. - A table that loses total_recorded_crime or violence_against_the_person says so, not a KeyError later in a need. - _frames' header matcher sets marks aside on both sides, so low income and crime pass their header's text and drop their own matchers. - The edition is found with _govuk.listed, and a constant used once is gone. - In the datasets test, _for_areas adds up councils in one area, and says which councils it leaves out. Signed-off-by: billlyzhaoyh <billlyzhaoyh@users.noreply.github.com> Github-Issue: #210
From code review. Each of the first three has a test that failed before: - The analyses said offences "live in" places, as if they were people: "97.1% of the offences recorded live in ...". NeedWords now carry who, live_in and their, so offences "are in" places, a share label reads "offences recorded that are in ...", and access and distance counts each offence at the centre of "its" local authority. Words for people, households and children are unchanged. need-reach's caveat says a count that is not of people is read as more or less reach between places. - A partnership's figures are taken away only when its note says its offences are "recorded under an unassigned" group, as ONS words it for Kent. ONS has other notes that mention unassigned offences, such as Humberside's, which says its figures remain accurate. - Offences whose headings would give one column, such as a total that includes fraud beside the one that leaves it out, or one with no name, are refused rather than one taking the other's place. Also: - A figure written as text, such as "1,234 [r]", is read; a negative count, which ONS says can happen, is missing. - The edition's name starts lower case, as a sentence says it, whatever case ONS gives it in, and a null description is no longer an AttributeError. - The reason for the needs no longer says every crime is recorded. - The docstrings that list need sources name ONS. - The live check fetches once, because ONS limits how often it is asked. - The dataset's areas carry their year. - The docs give Kent's partial figures as they are, such as Dartford and Gravesham's 11,165. Signed-off-by: billlyzhaoyh <billlyzhaoyh@users.noreply.github.com> Github-Issue: #210
|
This was referenced Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last of #210's three sources. Police recorded crime becomes a need, counted in offences, as decided on 1 December. There are two needs,
recorded_crimeandviolence_against_the_person, for England and Wales. They are published by community safety partnership and shared out to councils by residents (#218).Where the figures come from
ONS discontinued its dataset "Recorded crime data by Community Safety Partnership area" in October 2024. The figures moved to "Crime in England and Wales: Police Force Area data tables", published quarterly. The latest edition is the year ending June 2026, and the next is due 28 January 2027.
A new loader,
uk_open_data.crime.load_crime():<page>/data.Table C2: one row per partnership, 314 in all, with one column per kind of offence (23). Every partnership code matches the shipped lookup.The needs
needrecorded_crimeviolence_against_the_personNeedWordsfields,who,live_inandtheir. Their defaults keep every existing need's wording unchanged.Small shared fixes
_frames._first_cell_issets note marks aside, so the low income loader drops its own header matcher.Review
/simplify:Skipped:
download_need_figuresclears the cache each time. Homelessness, low income and vaccinations already do this, so the fix belongs in the shared step, as a follow-up;/code-review: three things to fix, each with a check I ran against the code before the fix to see it fail:Also fixed:
Tests
These are the seven tests agreed in the plan, in
tests/test_crime_api.pyandtests/test_crime_needs.py:Existing tests changed:
kept_figures: it now keys each need's invented figures by the need's own kind of area, using the shipped lookup. Partnership codes aren't council codes.Checks run
On main 09278d8:
ruff check,ruff format --check,ty check srcand ast-grep, as CI runs it;pytest: 1,293 passed;mkdocs build --strict.Live:
need-reachruns on both needs;_frames: low income, fuel poverty, homelessness and vaccinations.AI tools
Claude Code wrote the change, its tests and this description, and ran the reviews.