Repository navigation
fixes deprecation warning - #697
tomjemmett wants to merge 3 commits into
Conversation
copy argument is deprectated in pandas 3.0
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #697 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 1216 1216
Branches 61 61
=========================================
Hits 1216 1216 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ A new build is available.You can use the following to use pull the image into your local environment: docker pull ghcr.io/the-strategy-unit/nhp_model:pr-697 |
There was a problem hiding this comment.
🟡 Changes recommended
The newly added test converts between differing dtypes, so it always copies regardless of the copy argument and therefore fails to guard the intended behavior change, and it carries an unused mocker fixture.
1 open finding
What changed in this PR
This PR removes the deprecated copy=False keyword argument from .astype() calls across the model package. In pandas 3.0 the copy argument to astype is deprecated (Copy-on-Write makes it a no-op), so dropping it silences the deprecation warning while preserving behavior (the default copy=True is equally safe, and all dtype-changing conversions allocate new arrays anyway). A new unit test is added to document the non-mutation assumption.
Changes:
- Removed
copy=Falsefrom.astype()calls in model, inpatients, outpatients, aae, activity_resampling, results, and run modules. - Simplified a test fixture to build the array via
np.array(..., dtype=np.float64)instead of.astype(..., copy=False). - Added
test_pandas_astype_copies_to_prevent_mutationasserting the original Series is not mutated afterastype.
| File | Description |
|---|---|
| tests/unit/nhp/model/test_activity_resampling.py | Simplifies fixture dtype construction; adds a new test for astype non-mutation (test does not actually exercise the copy=False removal). |
| src/nhp/model/run.py | Drops copy=False from the pandas DataFrame astype used when printing step counts. |
| src/nhp/model/results.py | Drops copy=False from the SDEC patch value column cast. |
| src/nhp/model/outpatients.py | Drops copy=False from the NumPy counts cast. |
| src/nhp/model/model.py | Drops copy=False from several NumPy/pandas casts (years, merge cols, sampling). |
| src/nhp/model/inpatients.py | Drops copy=False from counts/sampling/LOSR casts while preserving np.int32 for speldur. |
| src/nhp/model/activity_resampling.py | Drops copy=False from the merged factor cast. |
| src/nhp/model/aae.py | Drops copy=False from the arrivals counts cast. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
was added by copilot, isn't useful

copy argument is deprectated in pandas 3.0