Stop dft_rast_classify() modifying the caller's raster (#89) - #93
Merged
NewGraphEnvironment merged 7 commits intoSep 30, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
set.cats() works in place and was called on the caller's own SpatRaster, so classifying turned the original into a factor named class_name. Set the colour table first: `coltab<-` deep-copies before it sets, so set.cats() now only reaches that copy. Output is identical to the old order and no second copy is made, as an explicit deepcopy() would. A new test checks file-backed, in-memory and list-element inputs. It is red on the old order with 6 failures. Removes the test-dft_accuracy_sample.R comment that worked around the bug. Code-check: three rounds, all clean. Fixes #89 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN
NewGraphEnvironment
deleted the
89-dft-rast-classify-mutates-the-caller-s-r
branch
September 30, 2026 00:31
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.
Summary
dft_rast_classify()no longer modifies the caller's raster. It called the in-placeterra::set.cats()on the object it was given. Nowcoltab<-runs first, which deep-copies, and the levels are set on that copy. The output isidentical()to 0.19.0 (cats()andcoltab()), and no extra copy is made.test-dft_accuracy_sample.Ris removed.Related Issues
Scale check (BULK, per CLAUDE.md)
BULK
classified_2017.tif(169,248,352 cells), terra 1.9.50. Kernel max RSS from/usr/bin/time -l, two reps each:deepcopy()first (the issue's proposal)deepcopy()would add 1.25 GiB per year classified in memory, so it was not used. The classify call itself takes 0.8–0.9 s on both main and this branch. The first attempt used a 2 spssampler, which cannot catch a sub-second peak: it read 0.26 GiB. I first blamed sampling the wrong PID, and retracted that after checking. The archive README records the full chain.Test plan
devtools::test():[ FAIL 0 | WARN 0 | SKIP 15 | PASS 1318 ]/code-check: three rounds, all clean. Reviewers confirmed thatcoltab<-copies at the terra 1.8-10 floor, that old and new orders give identical output on nine input shapes, and that no caller relied on the mutation.🤖 Generated with Claude Code
https://claude.ai/code/session_01PRhUJsuKABLfpBGktPoiBN