Skip to content

adds a helper method for extacting data - #286

Merged
tomjemmett merged 10 commits into
mainfrom
add_extract_null_checks
Sep 23, 2026
Merged

tomjemmett merged 10 commits into
mainfrom
add_extract_null_checks

Conversation

@tomjemmett

Copy link
Copy Markdown
Member
  • checks for any nulls in columns
  • prints a message about how many rows are going to be extracted
  • centralises the extraction logic

fixes #145

@tomjemmett
tomjemmett force-pushed the add_extract_null_checks branch 2 times, most recently from 8c3634b to e8eea85 Compare September 10, 2026 20:04
- checks for any nulls in columns
- prints a message about how many rows are going to be extracted
- centralises the extraction logic
@tomjemmett
tomjemmett force-pushed the add_extract_null_checks branch from e8eea85 to 273c428 Compare September 10, 2026 20:26
@tomjemmett
tomjemmett marked this pull request as ready for review September 22, 2026 10:47
Copilot AI lite review requested due to automatic review settings September 22, 2026 10:47
@tomjemmett
tomjemmett requested a review from a team as a code owner September 22, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new shared null-check/extract helper has correctness and reliability gaps (assert-based enforcement, NA/NaN handling, and avoidable repeated Spark recomputation) that should be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 4 Medium severity · 1 Low severity

Open (5)
What changed in this PR

This PR refactors the model-data extract scripts to centralize the common “write parquet + partitioning” logic into a shared decorator, and adds extract-time validation to catch missing values (related to #145).

Changes:

  • Introduces a shared @extract(...) decorator and check_extract_for_nulls(...) helper to standardize extraction and (optionally) null-check outputs.
  • Updates multiple extract scripts to return DataFrames and delegate writing/partitioning to the decorator.
  • Adds a row-count log message during extracts and per-extract column-exclusion lists for null checks.
File Description
src/​nhp/​data/​model_data/​helpers.py Adds shared extraction decorator and null-check helper.
src/​nhp/​data/​model_data/​op.py Migrates OP extract to decorator-based pattern and returns DF.
src/​nhp/​data/​model_data/​ip.py Migrates IP extract to decorator-based pattern and returns DF.
src/​nhp/​data/​model_data/​aae.py Migrates A&E extract to decorator-based pattern and returns DF.
src/​nhp/​data/​model_data/​ip_tpmas.py Splits TPMA extracts into two decorated extract functions.
src/​nhp/​data/​model_data/​ip_functional_areas.py Splits functional-area extracts into two decorated functions.
src/​nhp/​data/​model_data/​inequalities.py Migrates inequalities extract to decorator-based pattern (null checks off).
src/​nhp/​data/​model_data/​demographic_factors.py Migrates demographics extract to decorator-based pattern and returns DF.
src/​nhp/​data/​model_data/​birth_factors.py Migrates births extract to decorator-based pattern and returns DF.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/nhp/data/model_data/helpers.py Outdated
Comment thread src/nhp/data/model_data/helpers.py
Comment thread src/nhp/data/model_data/helpers.py Outdated
Comment thread src/nhp/data/model_data/helpers.py Outdated
Comment thread src/nhp/data/model_data/ip_functional_areas.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new extract decorator can leak persisted DataFrames on exceptions and includes a misleading null-check error message, which should be corrected before merging.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (5)
Previously missed (1)

In code that hasn't changed since last review

Low severity Inconsistent PySpark import style

src/​nhp/​data/​model_data/​inequalities.py:7

DataFrame is imported from pyspark.sql.dataframe while SparkSession is imported from pyspark.sql; this is inconsistent with the other model_data extract modules and can be simplified to a single import statement.

Comment thread src/nhp/data/model_data/helpers.py
Comment thread src/nhp/data/model_data/helpers.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

A few issues in the new shared helper (misleading error/doc text and missing wrapper metadata preservation) should be addressed to avoid confusion and improve maintainability.

Review effort: Lite
Findings: None

Resolved since last review (2)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Decorator drops function metadata without functools.wraps

src/​nhp/​data/​model_data/​helpers.py:132

The extract decorator wraps the original function but does not preserve its metadata (name/docstring/qualname), making stack traces and CLI help output less informative. Consider using functools.wraps (without copying annotations) so the decorated extract functions remain identifiable.

Low severity Docstring incorrectly describes null-value checks as null columns

src/​nhp/​data/​model_data/​helpers.py:93

Docstring says "null columns" but the function checks for null values within columns, which is misleading for anyone relying on this helper. Update the wording (and the exclude_cols type in the doc) to match the actual behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The refactor is cohesive and consistent across extract scripts, with only minor clarity issues (messaging/annotation readability) remaining.

Review effort: Lite
Findings: 3 Low severity

Open (3)

Comment thread src/nhp/data/model_data/helpers.py Outdated
Comment thread src/nhp/data/model_data/ip.py Outdated
Comment thread src/nhp/data/model_data/op.py Outdated
tomjemmett and others added 2 commits September 23, 2026 09:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@yiwen-h yiwen-h left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! the extract decorator is neat

@tomjemmett
tomjemmett merged commit 2b5515f into main Sep 23, 2026
3 checks passed
@tomjemmett
tomjemmett deleted the add_extract_null_checks branch September 23, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure there are no null/na values in model data extracts

3 participants