Skip to content

fix(raster): preserve complex samples through writes and translation - #841

Merged
giswqs merged 30 commits into
mainfrom
fix/complex-raster-writes
Nov 12, 2026
Merged

giswqs merged 30 commits into
mainfrom
fix/complex-raster-writes

Conversation

@giswqs

@giswqs giswqs commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Terrio writes complex NumPy rasters and preserves complex TIFF sample types through streamed GTiff/COG writes, updates, copies, CLI conversion and translation. Integer-complex copies preserve Int32 real and imaginary components exactly, including values above 2²⁴. Both native Raster and read-only rio APIs provide precise complex128 output, including big-endian dtypes and explicit output arrays.

Fixes #718.

Shared TIFF row writing retains the complex sample flag and real/imaginary pairing for pixel and band interleaving. Python construction and low-level row writers accept complex64/complex128 and explicit physical complex sample types. rio supports complex64, complex128 and complex_int16, preserving CInt16/CInt32 on copies and updates. Translation keeps complete component pairs and logical-band descriptions. Integer-complex writers use complex128 internal buffers for ordinary and file-backed writes and updates: CInt16 inputs round only once, while CInt32 components retain exact integer values. Spill selection and slab accounting include the full 16-byte complex sample.

Default complex read dtypes remain unchanged. Explicit complex128 reads preserve exact Int32 components before output conversion through whole reads, windows, nearest decimation, boundless windows and supplied output arrays. NumPy dtype objects and byte order are retained by Raster.read and array. Real out_dtype casts follow NumPy’s real-component conversion and warnings. Incomplete component-pair translation remains a real-component operation.

Validation in a local environment with GDAL 3.13.3:

  • A freshly packaged optimized Python/embedded-CLI module passes 1,063 affected complex, boundless, COG overview, rio, warning and resource-limit tests, one skipped. Strict mypy and stubtest (52 modules) pass.
  • Six new CInt16 window-write comparisons match GDAL exactly across GTiff/COG and memory/spill thresholds; four preceding-package controls failed from double rounding. Actual failing controls also cover concurrent native-handle borrowing, precise boundless writer reads, contradictory physical selectors and unchecked complex copy buffers. The fixes retain exact values and preserve typed resource refusals.
  • Linux child processes impose a 128 MiB usable-memory policy on real GDAL-authored CInt32 inputs. Rio copies, native reads and NumPy conversion refuse 144 MiB results and a 64 MiB result whose known conversion buffers require 160 MiB, while small complex128 windows retain exact components. Conversion admission also applies to real rasters. Native window allocation is checked by the native reader; NumPy conversion is admitted after that read and before its working buffers are allocated. Checks cover the known output/conversion buffers; this is not a total-process RSS cap.
  • The shared writer passes 32 native writer tests (10 existing ignored) and 33 resource-limit integration tests. Its fresh release WASM package passes 185 Node tests with 71 optional-data skips; the subsequent fixes change Python bindings only. The local WASM build skips optional wasm-opt postprocessing, with release profiles unchanged.
  • Independent GDAL-authored inputs and decoding check values, physical complex types, masks, nodata and georeferencing, including a real Landsat-derived complex grid. Formatting, workspace Clippy with warnings denied and changed-file pre-commit pass. No compressed-byte identity is claimed.

The source-backed CInt32 copy regression measured the same 131,641 HTTP body bytes in four requests before and after its chunk-budget correction. The largest returned complex128 buffer fell from 134,217,728 to 67,108,864 bytes; total returned buffers remained 134,217,728 bytes. This measures returned buffers, not peak process RSS. Whole-array construction may hold temporary component and converted integer buffers simultaneously; the returned-buffer bound is not a total process-memory limit. Compressed-byte identity with GDAL is not claimed.

Unresampled and nearest complex reads are validated. Other interpolation methods compute components separately; their complex results have not been validated against GDAL. An explicit copy dtype overrides the source physical sample type and may reduce precision. Negative-to-unsigned output follows the existing final cast policy; exact positive component preservation does not imply GDAL-equivalent negative saturation.

Final copy-path correction in 2ec26a2: open readable CInt16 writers retain their unrounded complex128 components during copies, and CInt16 copy chunks use the corresponding 16-byte budget. The existing near-half-value GDAL regression now copies the open writer before closure across GTiff/COG and spill limits. A focused Python precision control and full-repository pre-commit pass. The locally installed native extension predates CInt16 writer support, so its six integration cases cannot validate this matrix; CI rebuilds the PR extension and runs the extended regression. Earlier optimized-package results above predate this final correction.

Update-path correction: reopening a non-spilled CInt16 writer in r+ mode now requests complex128 components, preserving near-half inputs until their final integer conversion. The GDAL window-write regression now covers both w+ and r+ modes across both drivers and all three spill thresholds. Full-repository pre-commit passes. The expanded integration matrix requires the rebuilt CI extension; the older locally installed extension cannot validate it.

Documented limits (2f07cdf): exact CInt32-component output applies to direct Raster and terrio.rio dataset reads. WarpedVRT complex working dtypes remain unsupported. Raster.from_array keeps native component storage and may make a contiguous NumPy copy; those constructor copies are outside read working-memory admission. Documentation-only review follow-up passes changed-file pre-commit.

Summary by CodeRabbit

  • New Features
    • Added support for reading, creating, writing, and copying complex GeoTIFF and COG data, including complex integer and floating-point sample types.
    • Added output dtype selection for raster reads and complex sample-type selection when creating rasters.
    • Complex band selection and translation now preserve paired components and associated metadata when applicable.
  • Bug Fixes
    • Improved precision when reading and copying complex integer data, including CInt32.
  • Documentation
    • Expanded guidance on complex raster conversion, resampling, memory use, and supported compression.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds complex raster support across Rust GeoTIFF writing and translation, Python raster APIs, and rio read, write, and copy paths. It adds precision-preserving CInt32 reads and copies, complex-write conformance coverage, regression tests, and documentation.

Changes: Complex raster workflows

Layer / File(s) Summary
Rust complex translation and GeoTIFF layout
crates/terrio/src/pixel.rs, crates/terrio/src/lib.rs, crates/terrio/src/ops/translate.rs, crates/terrio/src/drivers/gtiff_write.rs, crates/terrio/tests/geotiff_complex.rs
A public helper collects real and imaginary components into supported raster data types. Translation retains complex status for valid component-pair selections and maps metadata by complex band. GeoTIFF planning groups component bands into complex samples. Tests cover translation, component selection, and interleave modes.
Python complex arrays and direct writers
python/src/raster.rs, python/src/cog_writer.rs, python/python/terrio/_terrio.pyi, python/tests/test_synthetic.py, js/tests/node.test.mjs
Raster.from_array accepts complex arrays and an optional component type. Raster.read and __array__ support output dtype selection. GeoTIFF and COG writers track complex status and component type. Tests cover invalid inputs and exact complex Int32 values.
rio reads, writes, and precision-preserving copies
python/python/terrio/rio/io.py, python/python/terrio/rio/shutil.py, python/python/terrio/rio/_boundless.py, python/python/terrio/rio/vrt.py, python/tests/test_rio_complex_writer.py
rio reads can use complex128 output to retain CInt32 component precision. Writer buffers, updates, and copy paths carry complex sample types. Tests cover complex writes, reads, updates, and copies.
Complex-write validation and documentation
scripts/conformance.py, scripts/tests/test_complex_writer_prerequisites.py, docs/python.md, docs/testing.md, python/README.md
The conformance suite registers complex-write tests and checks prerequisites. Documentation describes complex storage, precision, supported operations, and test coverage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Copy as rio.shutil.copy
  participant Reader as DatasetReader
  participant Writer as DatasetWriter
  participant Raster as Raster.from_array
  participant Tiff as TiffRows.create
  Copy->>Reader: Read CInt32 window through _read_for_copy as complex128
  Copy->>Writer: Pass source window and complex sample type
  Writer->>Raster: Build raster from complex array
  Raster->>Tiff: Plan complex GeoTIFF samples
Loading

Possibly related PRs

  • opengeos/terrio#862: Adds complex-aware row-buffer memory checks to the same GeoTIFF and COG writer paths.
  • opengeos/terrio#597: Adds an owned translation path that uses the translation logic changed here, and also modifies GeoTIFF row writing.

Suggested reviewers: gmoralessanchez, nkarasiak

Merge Risk: Minimal · up to 2f07c

The change preserves complex sample types and exact CInt32 values through writes, copies and reads. No outstanding merge-blocking issue remains. Complex interpolation other than nearest-neighbour is documented as unvalidated against GDAL and is out of scope for this change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(raster): preserve complex samples through writes and translation" matches the main change. The raw summary and PR objectives show complex-sample preservation in GTiff/COG writes, copies…
Linked Issues check Passed Assessed against [#718], the only active directly linked issue. Requirement group 1 [#718], rio writes: python/python/terrio/rio/io.py adds complex64 and complex128 to supported dtype names. DatasetWr…
Out of Scope Changes check Passed Changes map to [#718] or support its implementation. Rust writer and translation changes (gtiff_write.rs, translate.rs, pixel.rs complex_components_from_iter, lib.rs re-export) implement complex sampl…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(raster): preserve complex samples through writes and translation" matches the main change. The raw summary and PR objectives show complex-sample preservation in GTiff/COG writes, copies, updates, and translation (translate.rs, gtiff_write.rs, rio io.py, and the Python/Rust writer changes). The title is specific and does not describe anything absent from the changeset.

Full details: Linked Issues check

Explanation

Assessed against [#718], the only active directly linked issue. Requirement group 1 [#718], rio writes: python/python/terrio/rio/io.py adds complex64 and complex128 to supported dtype names. DatasetWriter validates complex sample-type hints and allocates complex128 buffers for CInt16 and CInt32. Streamed writes, updates and flushing carry the sample type. python/src/raster.rs and cog_writer.rs keep complex status and component dtype for GeoTiffWriter and CogWriter. Requirement group 2 [#718], copies: shutil.py sets complex64 or complex128 output for CInt16 and CInt32 sources and records the source sample type in _complex_dtype. Copy slabs use 16-byte items for these types. The issue asks that CInt32 values above 2^24 survive copies. Exact complex128 component reads (Raster.read, array, boundless and whole/window reads) support this. Requirement group 3 [#718], GTiff translation: crates/terrio/src/ops/translate.rs keeps complex status for I16, I32, F32 and F64 outputs when selected bands form complete component pairs, and maps band metadata by pair. Automated tests cover these paths: python/tests/test_rio_complex_writer.py, crates/terrio/tests/geotiff_complex.rs and js/tests/node.test.mjs. The author reports the CInt16 near-half-value GDAL regression and the r+ update path as covered by the expanded matrix. That matrix needs a rebuilt CI extension, so its results are not verified here. This assessment relies on the whole-PR change summary and the previous assessment. No repository inspection was made. Current requirements appear met by the described code and tests.

Full details: Out of Scope Changes check

Explanation

Changes map to [#718] or support its implementation. Rust writer and translation changes (gtiff_write.rs, translate.rs, pixel.rs complex_components_from_iter, lib.rs re-export) implement complex sample preservation for GTiff and COG. Python rio, shutil, cog_writer.rs and raster.rs changes implement writes, copies and sample-type preservation. Read-API changes (out_dtype, complex128 reads, boundless out_dtype) support the exact CInt32 copy and read precision that the issue requires. Resource-limit admission checks apply to the new complex128 and conversion buffers that these reads allocate. Native-handle borrowing and contradictory physical-selector fixes affect the same complex read and write paths. Docs, type stubs, the complex-writes conformance suite and its prerequisite test validate the same behavior. No change was found that is unrelated to complex raster writes, copies, reads or translation. This assessment relies on the whole-PR change summary and the previous assessment. No repository inspection was made.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each complex band,
Two planes meet as planned.
Int32 keeps its value bright,
Through COG and GeoTIFF write.
With tests complete, the carrots wait,
The pixels hop out straight.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fc75d79f-2c28-47c7-85a9-3f9d14918b3c
Commits

Reviewing files that changed from the base of the PR and between d980658 and 2f07cdf.

Files selected for processing: 15

  • crates/terrio/src/drivers/gtiff_write.rs
  • crates/terrio/src/lib.rs
  • crates/terrio/src/ops/translate.rs
  • docs/python.md
  • docs/testing.md
  • js/tests/node.test.mjs
  • python/README.md
  • python/python/terrio/rio/_boundless.py
  • python/python/terrio/rio/io.py
  • python/python/terrio/rio/shutil.py
  • python/python/terrio/rio/vrt.py
  • python/src/cog_writer.rs
  • python/src/raster.rs
  • python/tests/test_rio_complex_writer.py
  • scripts/conformance.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@giswqs
giswqs enabled auto-merge (squash) November 11, 2026 05:09
Comment thread python/python/terrio/rio/io.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed the full diff against main: the Rust pixel, GTiff/COG writer and translate changes, the PyO3 bindings, the terrio.rio Python layer, the new tests, and the conformance suite. I posted one inline comment, on a confirmed bug. The Rust side could not be compiled or run here, so the Rust logic is checked by reading only.

Bugs

  • Wrong error message for unsupported complex-integer dtypes (python/python/terrio/rio/io.py:2277), confidence high. The complex_int guard sits inside the try whose except Exception replaces every error with "A valid dtype is required.". The type is still TypeError, but the intended message is lost. Inline comment posted with a fix.
  • Silent precision loss for non-DatasetReader copy sources, confidence low. _read_for_copy only takes the exact-CInt32 path when type(self) is DatasetReader. WarpedVRT subclasses DatasetReader, so a CInt32 WarpedVRT source falls back to read(), which returns complex64 and rounds components above 2²⁴. Probably out of reach in practice, since warping complex data may not be supported, but the fallback is silent.
  • Band metadata mapping for incomplete pairs in translate_pixels (crates/terrio/src/ops/translate.rs:452), confidence low. The non-complex branch indexes ds.band_metadata by real band (b - 1), while the complex branch indexes by complex band ((p[0]-1)/2). For a complex source with an unpaired band, metadata can come from the wrong complex band. This line predates the PR, so I'm noting it rather than requesting a change.

Security

  • None found. The new inputs (out_dtype, complex_dtype, the copy windows) are parsed through NumPy dtype checks or the existing window and bounds paths.

Performance

  • Precise CInt32 reads and copies double the buffer from complex64 to complex128. This is the intended trade-off and is documented. The Rust raster_array_data also makes one extra copy of each complex array (ascontiguousarray plus the component Vec). Both are fine for correctness, but worth knowing for very large rasters.

Quality

  • _complex_sample is set only in the write branch of DatasetWriter.__init__ and read elsewhere via getattr(self, "_complex_sample", None) (around io.py:3032 and :3256). Declaring it as a class default next to _copy_of: Any = None (around io.py:2203) would remove the getattrs. _complex_int is redundant with _complex_sample == "CInt16".
  • Raster.read(out_dtype=...) on a complex raster with a real target calls astype, which silently drops the imaginary part (NumPy only emits a ComplexWarning). Consider raising instead, or documenting it.
  • The new test_complex_copies_preserve_physical_type_and_values uses small integer values for every kind, including CFloat64. It checks the DataType, but the value assertion cannot detect a float64 precision loss. A large-magnitude CFloat64 case would close that gap.
  • Python streaming writes with INTERLEAVE=BAND for complex data are not covered by the Python tests (the Python tests use the default pixel interleave). The Rust test covers band interleave through LazyRaster::write.

CLAUDE.md (AGENTS.md)

  • No changelog edit, and the PR body opens with a changelog-style paragraph. Both comply.
  • Conformance registration, the docs/testing.md and docs/python.md updates, and the .pyi stubs are all present. The Python read/from_array signatures in the stub match the Rust PyO3 signatures.
  • AGENTS.md asks that options be exposed consistently across public surfaces. complex_dtype and out_dtype exist only in Python. The JavaScript and CLI surfaces get the copy fix but not the explicit precise-read or complex-dtype options. This may be intentional scope, so I'm flagging it for the author to confirm.
  • The new Python test file has no SPDX header. The other test files mostly don't either, and the file is not a port, so this is a non-issue.

Change size

Compared with the base branch (merge base 4cf5683 to PR head ecc3bc2).

Metric Value
Files changed 15 (1 added, 14 modified, 0 removed, 0 renamed)
Size before 1.27 MB (1,335,345 B)
Size after 1.30 MB (1,357,994 B)
Total size change +22.1 KB (+22,649 B)
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 7.0 KB +7.0 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 13.5 KB +2.7 KB
js/tests/node.test.mjs 254.9 KB 256.6 KB +1.7 KB
python/python/terrio/rio/io.py 137.2 KB 138.6 KB +1.4 KB
scripts/conformance.py 184.3 KB 185.7 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 55.1 KB 56.0 KB +0.9 KB
docs/testing.md 177.7 KB 178.2 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.5 KB 81.9 KB +0.4 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.3 KB +0.3 KB
python/python/terrio/_terrio.pyi 82.0 KB 82.1 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 221.8 KB 221.8 KB +0.1 KB
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +0.0 KB

Preserve the specific unsupported integer-complex dtype error and exercise direct writer validation.
Comment thread crates/terrio/src/ops/translate.rs Resolved
Comment thread python/python/terrio/rio/shutil.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • translate.rs:451: translating a complex source with an incomplete component pair assigns the wrong band metadata. The else branch indexes the per-logical-band band_metadata with raw band numbers. Inline comment posted with a suggestion. Confidence: ~80%.

Security

  • Nothing found. Inputs are dtype strings and numeric arrays, and the conversions are bounded.

Performance

  • shutil.py:242: the 64 MiB chunk estimate assumes 8 bytes per sample, but CInt32/CFloat64 copies now read as complex128 (16 bytes). Inline comment posted. Confidence: medium.
  • raster.rs (read, __array__): when out_dtype is given, the result is always passed through astype, which copies even when the dtype already matches. Minor. Confidence: high, low impact.

Quality

  • raster.rs (__array__ and read): np.dtype(d).name drops byte order, so np.asarray(raster, dtype=">f4") now returns native-endian data, where it used to return big-endian. Untested. Confidence: high.
  • raster.rs:1327 (PyGeoTiffWriter.write): a complex array is silently converted to the writer's complex sample type (complex128 into complex64, or complex into CInt16 with rounding). Real-typed writers reject a dtype mismatch, so the two paths behave differently for direct Rust-level callers. The Python layer may cast first, so this may be intended. Confidence: medium. Worth a doc note or a decision.
  • io.py:2261: _complex_dtype is a private kwarg, but it is reachable through the public rio.open kwargs and is not checked against dtype. Confidence: medium.
  • Test coverage: the new Rust test covers only complete pairs. The partial-pair metadata case from the first finding has no regression test.

CLAUDE.md (AGENTS.md)

  • Checked and compliant: CHANGELOG untouched, the PR description opens with a changelog-style paragraph, the GDAL 3.13.3 reference is in doc comments, identifiers are behavior-named, conformance suite is registered, docs/testing.md and docs/python.md are updated, and _terrio.pyi matches the new signatures.
  • Possible gap: the new options (out_dtype, complex_dtype, dtype="complex_int16") are exposed only in Python. AGENTS.md asks for options to be consistent across public surfaces. The PR may defer this deliberately. Confidence: low.

Checked and found correct

  • The gtiff_write.rs planar chunk counts match Level::image.
  • The _OverviewRaster.read path maps overview=None to its own level, so _read_for_copy reads the right overview.
  • _getnpdtype maps complex_int* to complex64.
  • Compression refusal for unsupported complex codecs is present.
  • The conformance --only/--strict flags and the gdal and data_dir fixtures exist.
  • I did not run the tests. I checked the code by reading it.

Change size

Compared with the base branch (merge base 4cf5683 to PR head daea750), not the latest push.

Measure Value
Files changed 15 (1 added, 14 modified, 0 removed, 0 renamed)
Size before 1.27 MB
Size after 1.30 MB
Total size change +22.0 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 7.3 KB +7.3 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 13.5 KB +2.7 KB
js/tests/node.test.mjs 254.9 KB 256.6 KB +1.7 KB
python/python/terrio/rio/io.py 137.2 KB 138.6 KB +1.4 KB
scripts/conformance.py 184.3 KB 185.7 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 55.1 KB 56.0 KB +0.9 KB
docs/testing.md 177.7 KB 178.2 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.5 KB 81.9 KB +0.4 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.3 KB +0.3 KB
python/python/terrio/_terrio.pyi 82.0 KB 82.1 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 221.8 KB 221.8 KB +0.1 KB
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +0.0 KB

Keep logical-band metadata on individual complex components, account for complex128 copy buffers, and update the obsolete complex-array refusal test.
Comment thread python/python/terrio/rio/shutil.py Resolved
Comment thread python/src/raster.rs Resolved
Comment thread python/python/terrio/rio/io.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff and the surrounding code for the risky spots. I found no definite bugs. I could not compile or run the tests here (no Bash), so the PR's reported test results are unverified by me.

Bugs: None found. Checked and consistent:

  • The overview-copy path: _OverviewRaster forwards data_type and passes out_dtype through **kw.
  • layout.parts is 1 for real rasters, so their chunking is unchanged.
  • from_f64 rounds and saturates, matching the stated GDAL behaviour.
  • _copy_of and streaming sources are DatasetReader subclasses, so _read_for_copy is always available.

Security: None found. The changes are numeric conversion and dtype-name handling, with no external input reaching a dangerous sink.

Performance:

  • raster_array_data can copy a complex array up to three times: ascontiguousarray, the interleaved parts buffer, and convert_complex_components when the target type differs. Streamed writes pay this per chunk. Low confidence that it matters in practice. (Not posted.)

Quality:

  • complex_dtype in python/src/raster.rs accepts complex_int32, which the Python writer rejects and the docstring does not list. (Inline comment with a suggestion, medium confidence.)
  • The complex-integer dtype check at io.py:2279 repeats _is_complex_int from rio/dtypes.py. (Inline nit, high confidence.)

CLAUDE.md (AGENTS.md):

  • The shutil.py chunk budget now uses 16-byte items for CInt32 and CFloat64 sources. That halves the rows per window and roughly doubles source reads for those copies. AGENTS.md requires measuring files opened or bytes transferred for I/O changes, and the PR description has no such measurement. (Inline comment, medium confidence.)
  • The rest of AGENTS.md is followed: no CHANGELOG edit, the changelog-style opening paragraph is present, GDAL 3.13.3 is recorded in the convert_complex_components doc comment, names describe behaviour, and the conformance suite and docs are registered.

I posted three inline comments: shutil.py:242, raster.rs:233 and io.py:2279.

Change size

Compared with the base branch (main, merge base 4cf5683, PR head c935371), which covers the whole PR.

Measure Value
Files changed 16 (1 added, 15 modified, 0 removed, 0 renamed)
Size before 1.30 MB
Size after 1.32 MB
Total size change +22.8 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 7.5 KB +7.5 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
js/tests/node.test.mjs 254.9 KB 256.6 KB +1.7 KB
python/python/terrio/rio/io.py 137.2 KB 138.6 KB +1.4 KB
scripts/conformance.py 184.3 KB 185.6 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 55.1 KB 56.0 KB +0.9 KB
docs/testing.md 177.7 KB 178.3 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.5 KB 82.0 KB +0.5 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.3 KB +0.4 KB
python/python/terrio/_terrio.pyi 82.0 KB 82.1 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 221.8 KB 221.8 KB +0.1 KB
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +0.0 KB
python/tests/test_synthetic.py 25.7 KB 25.6 KB -0.0 KB

Document the native complex_int32 storage selector and reuse the shared complex-integer name check in writer validation.
Comment thread python/src/raster.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Read-only review of PR #841 (fix/complex-raster-writes). I could not run the tests or builds in this session, so every point below comes from reading the diff and the surrounding code.

Bugs

  • None confirmed. I traced the Rust paths (translate_pixels complex pairing, convert_complex_components, planar and interleaved chunking in gtiff_write.rs, raster_array_data) and the Python paths (_read_for_copy, _flush, _write_streaming, shutil._copy_dataset). I also checked the hand-built TIFF bytes and expected values in the JS test. Overview-opened CInt32 copies look correct: _OverviewRaster.__getattr__ delegates data_type to its base raster.

Security

  • None found. The change adds no external input handling beyond dtype-name parsing, which is validated.

Performance

  • None significant. The copy chunk sizing now counts 16-byte complex128 samples, which matches the in-memory array it allocates. The new I/O paths (_read_for_copy, the Int32-precise window read) do not add extra file opens or passes. The AGENTS.md guidance to measure files opened or bytes transferred for I/O changes is not reflected in the PR (low confidence that it matters here).

Quality

  • Low confidence (~50%), inline comment at python/src/raster.rs:618: read(out_dtype=...) on a complex raster passes a real dtype straight to astype, which silently drops the imaginary components.
  • Nits, not posted inline:
    • python/README.md adds two blank lines before ## Vector data.
    • convert_complex_components is re-exported from the crate root, which widens the Rust public API. This looks intentional for the Python binding, but confirm it is meant to be public.
    • scripts/conformance.py decides "skipped" by substring match on pytest output. This works, but it is fragile.

CLAUDE.md (AGENTS.md)

  • Compliant: CHANGELOG.md is not edited, and the PR opens with a changelog-style paragraph. The GDAL 3.13.3 reference is recorded in a doc comment. Test names describe behavior. No ported code, so no SPDX or NOTICE update is needed. The Python stubs are updated for the new keyword arguments.

Change size

Compared with main (merge base 4cf5683 to PR head 757a1c1). Sizes are file sizes, not line counts.

Measure Value
Files changed 17 (1 added, 16 modified, 0 removed, 0 renamed)
Size before 1.32 MB
Size after 1.34 MB
Total size change +23.8 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 7.5 KB +7.5 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
js/tests/node.test.mjs 254.9 KB 256.6 KB +1.7 KB
scripts/conformance.py 184.3 KB 185.6 KB +1.3 KB
python/python/terrio/rio/io.py 137.2 KB 138.5 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 55.1 KB 56.0 KB +0.9 KB
python/README.md 21.2 KB 21.8 KB +0.6 KB
docs/testing.md 177.7 KB 178.3 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.5 KB 82.0 KB +0.5 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.3 KB +0.4 KB
python/python/terrio/_terrio.pyi 82.0 KB 82.1 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 221.8 KB 221.8 KB +79 B
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +30 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB -8 B

Comment thread python/src/raster.rs Resolved
Comment thread crates/terrio/src/ops/translate.rs Resolved
Comment thread python/python/terrio/rio/io.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • No confirmed correctness bugs. The complex-pair handling in translate_pixels, the planar parts arithmetic in gtiff_write.rs, and the _OverviewRaster forwarding in _read_for_copy all check out on reading. Confidence: high for the paths I traced.
  • Possible label issue: a complex source written to non-complex output (e.g. output_type=U8 with a full pair) gives both real outputs the same band description. crates/terrio/src/ops/translate.rs:451. Confidence: low, and it is a question about intent.
  • Silent precision fallback for subclasses: type(self) is DatasetReader skips WarpedVRT and other subclasses, which then round CInt32 to complex64 without error. python/python/terrio/rio/io.py:1495. Confidence: low; I did not confirm a CInt32 WarpedVRT source reaches this path.

Security

  • None found. The changes add no I/O, subprocess or path handling beyond existing code. scripts/conformance.py only runs a fixed pytest path.

Performance

  • raster_array_data (python/src/raster.rs:262) can hold several full-size buffers at once for whole-array from_array calls: the input, a contiguous copy, the f64 component vector and the converted vector. Confidence: medium.

Quality

  • python/README.md has a doubled blank line before "## Vector data". Nit.
  • python/src/raster.rs now uses complex_dtype as both a free function and a parameter name, and the call is qualified as self::complex_dtype. This works but is easy to misread. Nit.
  • crates/terrio/src/lib.rs now publicly exports convert_complex_components, which takes a wbraster type. Only the Python binding uses it. Consider keeping it crate-private unless the Rust API needs it. Nit.

CLAUDE.md / AGENTS.md

  • The PR does not edit CHANGELOG.md and its body opens with a changelog-style paragraph, as required.
  • Test and function names describe behaviour, and GDAL 3.13.3 is recorded only in doc comments.
  • Validation evidence is in the PR body. I could not run the tests (no Bash access), so these claims are unverified here.

I checked the Python API surface against the stub: read(..., *, out_dtype) and from_array(..., *, complex_dtype) match the Rust signatures. The conformance flags --only and --strict exist. toBytes exists in js/src/lib.rs.

Change size

Compared with main (merge base 4cf5683 to PR head f82793a).

Measure Value
Files changed 17 (1 added, 16 modified, 0 removed, 0 renamed)
Size before 1.32 MB
Size after 1.34 MB
Total size change +24.0 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 7.5 KB +7.5 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
js/tests/node.test.mjs 254.9 KB 256.6 KB +1.7 KB
scripts/conformance.py 184.3 KB 185.6 KB +1.3 KB
python/python/terrio/rio/io.py 137.2 KB 138.5 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 55.1 KB 56.0 KB +0.9 KB
python/README.md 21.2 KB 22.0 KB +0.8 KB
docs/testing.md 177.7 KB 178.3 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.5 KB 82.1 KB +0.5 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.3 KB +0.4 KB
python/python/terrio/_terrio.pyi 82.0 KB 82.1 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 221.8 KB 221.8 KB +0.1 KB
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +0.0 KB
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

Sizes are file sizes from stats.json, not line counts. The stats are not truncated.

Preserve physical complex sample types and exact Int32 components in readable writer updates and copies. Account for complex128 storage in slab sizing and document whole-array allocation and metadata scope.
Preserve complex-write and WebP conformance documentation, suites and Node regressions.
Comment thread python/python/terrio/rio/io.py Resolved
Comment thread scripts/conformance.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the surrounding Rust (gtiff_write.rs, pixel.rs, translate.rs) and Python (io.py, shutil.py) code, and checked the complex-sample chunk/plane arithmetic against image(). I did not build or run the tests; this review is by reading only. Two inline comments are posted.

Bugs

  • rio.open(path).read(out_dtype="complex128") on a read-only CInt32 file rounds Int32 components to complex64 before the widening cast, so components above 2^24 are lost. Only Raster.read and the copy path are exact. Inline comment posted on python/python/terrio/rio/io.py. Confidence: about 75%.

Security

  • Nothing found.

Performance

  • Exact CInt32 copies and updates use complex128 buffers, which double memory per window. This is intentional and documented in the PR. No action needed.

Quality

  • Stray blank line splitting the suite list in scripts/conformance.py. Inline comment posted. Nit.
  • The private _complex_dtype kwarg on rio.open is not checked against dtype. A mismatch such as dtype="float32" with _complex_dtype="CInt16" only fails at close. Confidence: about 30%.
  • convert_complex_components is now re-exported from the core crate's public API, though it is only a helper for the bindings. Confidence: about 40%.
  • Conformance treats any skipped in pytest output as DIFFERS, so an optional skip (such as the Landsat fixture) fails the strict suite. Confidence: about 50%.
  • docs/python.md says copy preserves "CInt16 and CInt32 ... as well", but CFloat32 and CFloat64 are also preserved. Nit.
  • python/README.md has a double blank line before "## Vector data". Nit.

CLAUDE.md (AGENTS.md)

  • No CHANGELOG edit, test names follow behavior, and the GDAL reference is recorded in doc comments. Compliant.
  • The CLI and JS/WASM surfaces are not changed, so they inherit complex behaviour only through the core. Confidence that this is a gap: low (about 30%). Worth confirming the public surfaces are consistent.

Change size

Compared with the base branch (merge base 5a48730 to PR head f9dc62d), using whole-PR file sizes.

Measure Value
Files changed 17 (1 added, 16 modified, 0 removed, 0 renamed)
Size before 1.35 MB (1,413,004 B)
Size after 1.37 MB (1,441,130 B)
Total size change +27.5 KB (+28,126 B)
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 9.7 KB +9.7 KB
python/src/raster.rs 55.7 KB 59.7 KB +4.0 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
python/python/terrio/rio/io.py 137.2 KB 139.5 KB +2.2 KB
js/tests/node.test.mjs 264.8 KB 266.5 KB +1.7 KB
scripts/conformance.py 194.2 KB 195.5 KB +1.3 KB
crates/terrio/src/pixel.rs 6.8 KB 8.0 KB +1.3 KB
docs/python.md 57.9 KB 59.1 KB +1.1 KB
python/README.md 21.2 KB 22.0 KB +0.8 KB
docs/testing.md 185.3 KB 185.8 KB +0.5 KB
crates/terrio/src/ops/translate.rs 81.7 KB 82.2 KB +0.5 KB
python/python/terrio/rio/shutil.py 11.0 KB 11.4 KB +0.4 KB
python/src/cog_writer.rs 6.7 KB 7.1 KB +0.4 KB
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 220.0 KB 220.1 KB +0.1 KB
crates/terrio/src/lib.rs 18.6 KB 18.7 KB +30 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

@giswqs

giswqs commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 4 minutes.

Comment thread python/python/terrio/rio/io.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed the diff against the surrounding source. I could not build or run the tests (no shell here), so the findings below come from reading the code, not from execution.

Bugs

  • complex_int16 writes round twice (medium confidence). DatasetWriter buffers complex128 input as complex64 before the Rust side rounds to Int16. A value such as 2.4999999 can round up to 3 instead of 2, and Raster.from_array(..., complex_dtype="CInt16") does not have this problem, so the two APIs disagree. Inline comment posted with a suggested fix.
  • Real-raster reads can now be refused (medium confidence). The usable_memory admission in python/src/raster.rs runs after the native window is already allocated, and it applies to every read above 16 MiB, not only complex ones. The docstring's "refused before allocated" is only partly true. Inline comment posted.

Security

  • No issues found. The changes add no new input parsing beyond dtype names, which are validated against fixed sets.

Performance

  • No significant issues. The conversion-peak accounting adds bounded arithmetic only. Wider CInt16 buffers, if the fix above is adopted, double writer memory for that type; the slab and spill sizing should be re-checked.

Quality

  • The "wide read" predicate is repeated in three places (io.py read(), its boundless branch, and _boundless.py _source_read), with slightly different conditions. The boundless branch also reads the writer-only _buffer_dtype through getattr. Inline comment posted.
  • The sample-name tuples ("CInt16", "CInt32", "CFloat32", "CFloat64") and the related pairs are repeated across io.py and shutil.py. A module-level constant would keep them consistent. Nit.
  • docs/python.md lines 182–203 are one dense block with very long lines, and python/README.md repeats much of it. Consider splitting. Nit.

CLAUDE.md / AGENTS.md

  • CHANGELOG.md is not edited, and the PR body opens with a changelog-style paragraph, as required.
  • The new Python test module has no SPDX header. Most files in python/tests/ also lack one, so this is consistent with the directory. Nit.
  • The new complex selectors are Python-only. Nothing in the diff adds a CLI or MCP surface, so this does not violate the rule for new operations. Confirm that no CLI option is expected for this change.

Nothing was approved, merged, or modified.

Change size

Compared: the whole PR against main (merge base 433ed60 to PR head 6be7ce7).

Measure Value
Files changed 20 (added 2, modified 18, removed 0, renamed 0)
Size before 1.50 MB
Size after 1.54 MB
Total size change +51.8 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 24.3 KB +24.3 KB
python/src/raster.rs 56.4 KB 63.2 KB +6.9 KB
python/python/terrio/rio/io.py 139.3 KB 145.0 KB +5.7 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
docs/python.md 59.1 KB 61.1 KB +1.8 KB
js/tests/node.test.mjs 281.0 KB 282.7 KB +1.7 KB
scripts/conformance.py 202.0 KB 203.4 KB +1.4 KB
python/README.md 21.2 KB 22.5 KB +1.3 KB
scripts/tests/test_complex_writer_prerequisites.py 0 B 1.2 KB +1.2 KB
crates/terrio/src/pixel.rs 6.8 KB 7.7 KB +955 B
docs/testing.md 193.7 KB 194.2 KB +552 B
crates/terrio/src/ops/translate.rs 82.2 KB 82.7 KB +550 B
python/python/terrio/rio/_boundless.py 32.6 KB 33.1 KB +536 B
python/python/terrio/rio/shutil.py 11.5 KB 11.8 KB +354 B
python/python/terrio/rio/vrt.py 66.9 KB 67.2 KB +285 B
python/src/cog_writer.rs 6.7 KB 6.4 KB −266 B
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +108 B
crates/terrio/src/drivers/gtiff_write.rs 234.2 KB 234.3 KB +79 B
crates/terrio/src/lib.rs 18.7 KB 18.7 KB +32 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

- Keep CInt16 writer buffers in complex128 so integer components round once.
- Account for the wider storage in spill selection and slab budgets, with GDAL regressions.
- Document row-writer component conversion and NumPy allocation admission boundaries.
@giswqs

giswqs commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Final allocation update 6be7ce7 has been reviewed: output working-set accounting includes conversion buffers and dtype/endian casts; same-dtype astype uses copy=False. No new correctness blocker found in the incremental review. Please review the updated head.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread python/python/terrio/rio/io.py Resolved
Comment thread python/python/terrio/rio/shutil.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • python/python/terrio/rio/io.py:2697: DatasetWriter._read_for_copy returns exact complex128 only for CInt32. A readable CInt16 writer falls through to complex64, so copying it to CInt16 rounds twice (e.g. 2.4999999 becomes 3, not 2). Inline comment posted with a one-line fix. Confidence: high (~75%).

Performance

  • python/python/terrio/rio/shutil.py:253: the copy chunk budget counts CInt16 at 8 bytes per sample, but the writer materialises 16-byte complex128 rows, so peak memory is about 2x the 64 MiB budget. Inline comment posted with a fix. Confidence: medium-high (~70%).

Security

  • None found. The new from_array and read input paths validate dtype, byte order and shape before allocation, and the allocation check covers wide outputs.

Quality (nits, not posted inline)

  • python/python/terrio/rio/io.py (_io, around line 1644): partial(self._read_level, out_dtype=...) now passes a keyword that older third-party _read_level overrides do not accept, so a complex128 boundless or window read on such a subclass raises TypeError. Confidence: low-medium.
  • python/python/terrio/rio/io.py (_read_for_copy, around line 1528): the exact path reads self._raster directly, bypassing any subclass read() override. This is documented only for the no-override case. Confidence: low.
  • python/src/raster.rs:1007: from_array has a parameter named complex_dtype that shadows the free function complex_dtype, which is why it is called as self::complex_dtype. Renaming the function (e.g. complex_sample_type) would make this clearer.
  • python/src/raster.rs (read): the NumPy admission check runs after read_window has already allocated the native components, and it also applies to plain real reads. The docstring says this, but the name suggests a pre-allocation guard. Confidence: low.
  • python/src/raster.rs (from_numpy): the error message dropped the "integer or float32/float64" guidance.
  • python/tests/test_rio_complex_writer.py (test_integer_complex_window_rounding_matches_gdal): asserts on dst._data being a memmap and on a values.nbytes threshold. That ties the test to internal buffer strategy; behavioural assertions would be sturdier.
  • python/python/terrio/rio/io.py (DatasetReader.__init__): _complex_dtype is popped in read mode and silently ignored.

CLAUDE.md / AGENTS.md

  • The PR does not edit CHANGELOG.md, which is correct. It does not update ROADMAP.md. If the complex-write item is tracked there, it should be checked off when the scope is complete (AGENTS.md asks for this).
  • The new Python test file has no SPDX header. Other files in python/tests also lack one, so this is consistent with the directory and not a violation.

Checked: Rust Pixel::from_f64 rounding and saturation against the GDAL-matching claim, GTiff planar and interleaved parts handling, the overview-level path through _OverviewRaster.read(**kw), the _core_resampled exclusion of complex bands (so precise reads are not bypassed), translate.rs complex-pair detection and per-pair band metadata, and the conformance suite skip logic.

I did not run the test suite or build; these findings come from reading the staged diff and the surrounding source.

Change size

Compared with the base branch: the whole PR against main (merge base 433ed60 to PR head 3b52805).

Measure Value
Files changed 20 (2 added, 18 modified, 0 removed, 0 renamed)
Size before 1.50 MB
Size after 1.55 MB
Total size change +51.9 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 25.8 KB +25.8 KB
python/src/raster.rs 56.4 KB 63.8 KB +7.4 KB
python/python/terrio/rio/io.py 139.3 KB 145.1 KB +5.9 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
docs/python.md 59.1 KB 60.9 KB +1.9 KB
js/tests/node.test.mjs 281.1 KB 282.7 KB +1.7 KB
scripts/conformance.py 202.0 KB 203.4 KB +1.4 KB
python/README.md 21.2 KB 22.5 KB +1.3 KB
scripts/tests/test_complex_writer_prerequisites.py 0 B 1.2 KB +1.2 KB
crates/terrio/src/pixel.rs 6.8 KB 7.7 KB +955 B
docs/testing.md 193.7 KB 194.2 KB +552 B
crates/terrio/src/ops/translate.rs 82.2 KB 82.7 KB +550 B
python/python/terrio/rio/_boundless.py 32.6 KB 33.1 KB +536 B
python/python/terrio/rio/shutil.py 11.5 KB 11.8 KB +354 B
python/python/terrio/rio/vrt.py 66.9 KB 67.2 KB +285 B
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +108 B
crates/terrio/src/drivers/gtiff_write.rs 234.2 KB 234.3 KB +79 B
python/src/cog_writer.rs 6.7 KB 6.8 KB +65 B
crates/terrio/src/lib.rs 18.7 KB 18.7 KB +32 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

@giswqs
giswqs disabled auto-merge November 12, 2026 08:57
@giswqs
giswqs enabled auto-merge (squash) November 12, 2026 09:03
@giswqs

giswqs commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Final head 2ec26a2 fixes both verified CInt16 readable-copy precision and chunk-budget findings, extends the existing GDAL regression to copy an open writer, and adds the missing nested test-double docstrings. Full-repository pre-commit passes. Please review the updated head.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread python/python/terrio/rio/io.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • CInt16 r+ updates round twice (confidence about 80%). _open_update sets read_options only for CInt32, so a non-streaming CInt16 update loads complex64 while the buffer is complex128. A write of 2.4999999 becomes 2.5 in float32 and then 3, where GDAL and a fresh w+ writer give 2. The streaming branch is correct. Posted inline on python/python/terrio/rio/io.py:2639 with a one-line fix. The existing rounding test only covers w+, so it misses this.

Security

  • Nothing found. The new NumPy-side admission checks are on the read path and the subprocess test is fixed-argument.

Performance

  • Low confidence: the NumPy admission check now also runs for real rasters (python/src/raster.rs, around line 1219). For real rasters it re-checks the same native bytes the reader already admitted. Worth confirming it cannot refuse reads that succeeded before.
  • Complex CInt16 writer buffers double from 8 to 16 bytes per sample. This is intended and accounted for in spill selection, but it is a memory cost to note.

Quality

  • raster.rs from_numpy: the error message dropped the list of supported dtypes, so it is less helpful now.
  • python/tests/test_rio_complex_writer.py: the subprocess test re-imports sys, os and subprocess inside the function, shadowing the module-level sys.
  • _boundless.py: the boundless_read docstring wraps awkwardly ("(the dataset's type\n by default), and the mask (True where\n invalid)").
  • docs/python.md: the complex-read paragraph has very long lines; splitting it would help readability.

CLAUDE.md / AGENTS.md

  • Low confidence: the complex_dtype and out_dtype selectors are Python-only. The JS/WASM and CLI surfaces get the copy fix but no explicit selection. Check whether AGENTS.md's "expose applicable options consistently" rule applies to a bug fix like this.
  • No CHANGELOG.md edit, and GDAL 3.13.3 is recorded in the doc comments. These follow the repo rules.

Checked and not flagged: the Rust integer rounding (round() plus saturation matches the stated GDAL behaviour), the translate.rs band pairing and metadata, the _read_level and _io out_dtype plumbing (the complex-excluded core resampling path is correct), the _boundless and VRT overrides, and the usable_memory policy reads. I did not run the test suite or build; this is a review from reading the diff and source.

Change size

Compared: the whole PR against main (merge base 433ed60 to PR head 2ec26a2).

Measure Value
Files changed 20 (added 2, modified 18, removed 0, renamed 0)
Size before 1.50 MB
Size after 1.55 MB
Total size change +53.8 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 26.3 KB +26.3 KB
python/src/raster.rs 56.4 KB 63.8 KB +7.4 KB
python/python/terrio/rio/io.py 139.3 KB 145.1 KB +5.9 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.0 KB +3.2 KB
docs/python.md 59.1 KB 60.9 KB +1.9 KB
js/tests/node.test.mjs 281.1 KB 282.7 KB +1.7 KB
scripts/conformance.py 202.0 KB 203.4 KB +1.4 KB
python/README.md 21.2 KB 22.5 KB +1.3 KB
scripts/tests/test_complex_writer_prerequisites.py 0 B 1.2 KB +1.2 KB
crates/terrio/src/pixel.rs 6.8 KB 7.7 KB +955 B
docs/testing.md 193.7 KB 194.2 KB +552 B
crates/terrio/src/ops/translate.rs 82.2 KB 82.7 KB +550 B
python/python/terrio/rio/_boundless.py 32.6 KB 33.1 KB +536 B
python/python/terrio/rio/shutil.py 11.5 KB 11.8 KB +364 B
python/python/terrio/rio/vrt.py 66.9 KB 67.2 KB +285 B
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +108 B
crates/terrio/src/drivers/gtiff_write.rs 234.2 KB 234.3 KB +79 B
python/src/cog_writer.rs 6.7 KB 6.8 KB +65 B
crates/terrio/src/lib.rs 18.7 KB 18.7 KB +32 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

@giswqs

giswqs commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

Final head 2ec26a2 is CI-green and all known findings are addressed. Prior incremental requests were rate-limited. Please review the current complete diff; keep the normal approval checks.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 55 minutes.

Comment thread docs/python.md Resolved
Comment thread python/src/raster.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Checked the full diff against the surrounding source. The core paths hold up: the streamed GTiff/COG chunk accounting for planar complex is consistent, plane/parts are used the same way at every site, complex_to_numpy is still called (no dead-code Clippy failure), read_sampled returns None for complex so nearest decimation reaches the out_dtype-aware reader, and the overview wrapper forwards out_dtype. I did not run the test suite or build the code.

Bugs

  • terrio.rio VRTs silently drop exact complex reads. vrt.py:452 sets the working dtype to the source's dtypes[0] (complex64 for CInt32), so read(out_dtype="complex128") rounds components above 2^24. The code comment acknowledges this, but the user-facing docs state exact reads without that caveat. Confidence ~55%, not run. (Inline comment on docs/python.md:81.)

Security

  • None found.

Performance

  • raster_array_data (non-target path) copies non-contiguous complex input and then builds a second component Vec, roughly 2x peak memory. The new admission check does not cover from_array or writer inputs. Confidence ~45%. (Inline comment on python/src/raster.rs:284.)

Quality

  • Real-raster reads now go through the new conversion admission, so a read that succeeded before can raise ResourceLimitError on memory-limited hosts. The PR body discloses this, but it changes behavior for non-complex users. Worth calling out in the changelog text. Confidence 60% that it matters to users.
  • scripts/conformance.py maps any pytest failure in suite_complex_writes to DIFFERS, which reads as a pixel difference even when the failure is setup or environment. Confidence ~40%.
  • test_precise_complex_copy_checks_wide_output_before_allocation is Linux-only, writes a 1024×9216 CInt32 fixture, and runs subprocesses under a fixed 60 s timeout. It may be flaky on slow runners. Confidence ~35%.
  • docs/python.md and python/README.md repeat the same long complex paragraph. Consider one source of truth.

CLAUDE.md (AGENTS.md)

  • No CHANGELOG edit, and the PR body opens with a changelog-style paragraph. Compliant.
  • GDAL 3.13.3 is recorded in doc comments, not identifiers. Compliant.
  • New scripts/conformance.py suite is registered. Compliant.
  • New python/tests/test_rio_complex_writer.py has no SPDX header. Only 2 of 173 Python test files have one, so this doesn't contradict repo convention.

Change size

Compared with the base branch (merge base 433ed60 to PR head de3a59d), covering the whole PR.

Metric Value
Files changed 20 (2 added, 18 modified, 0 removed, 0 renamed)
Size before 1.50 MB
Size after 1.55 MB
Total size change +55.4 KB
Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 26.6 KB +26.6 KB
python/src/raster.rs 56.4 KB 63.8 KB +7.4 KB
python/python/terrio/rio/io.py 139.3 KB 145.2 KB +5.9 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.1 KB +3.2 KB
docs/python.md 59.1 KB 60.9 KB +1.9 KB
js/tests/node.test.mjs 281.1 KB 282.8 KB +1.7 KB
scripts/conformance.py 202.0 KB 203.4 KB +1.4 KB
python/README.md 21.2 KB 22.5 KB +1.3 KB
scripts/tests/test_complex_writer_prerequisites.py 0 B 1.2 KB +1.2 KB
crates/terrio/src/pixel.rs 6.8 KB 7.7 KB +955 B
docs/testing.md 193.7 KB 194.2 KB +552 B
crates/terrio/src/ops/translate.rs 82.2 KB 82.7 KB +550 B
python/python/terrio/rio/_boundless.py 32.6 KB 33.1 KB +536 B
python/python/terrio/rio/shutil.py 11.5 KB 11.8 KB +364 B
python/python/terrio/rio/vrt.py 66.9 KB 67.2 KB +285 B
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +108 B
crates/terrio/src/drivers/gtiff_write.rs 234.2 KB 234.3 KB +79 B
python/src/cog_writer.rs 6.7 KB 6.8 KB +65 B
crates/terrio/src/lib.rs 18.7 KB 18.7 KB +32 B
python/tests/test_synthetic.py 25.7 KB 25.6 KB −8 B

Comment thread python/src/raster.rs Resolved
Comment thread python/python/terrio/rio/io.py Resolved
Comment thread python/python/terrio/rio/io.py Resolved
Comment thread python/tests/test_rio_complex_writer.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs: I found no confirmed functional bug. I traced the main paths: complex write, copy, update, translate, and the read gating for precise CInt32 output. The read_resampled branch excludes complex dtypes, the overview reader forwards out_dtype correctly, _open_update runs after _load, and the copy profile's dtype override is not clobbered later. I could not run the tests (no Bash here), so the GDAL comparisons are unverified.

Security: none found. Subprocesses use fixed argument lists, and the conformance additions contain no injection surface.

Performance: nothing material. The precise CInt32 path doubles buffer size (16 B per sample) by design, and the PR describes this. The memory admission in raster.rs runs only above 16 MiB.

Quality:

  • python/src/raster.rs:226: the dtype error message dropped the list of supported dtypes. Suggestion posted. (high)
  • python/python/terrio/rio/io.py:2046: getattr(self, "_buffer_dtype", None) duck-types writers. Suggested a base-class property. (medium)
  • python/python/terrio/rio/io.py:2369: _complex_dtype is silently ignored in r/r+ modes. (medium)
  • Nit, not posted: python/src/raster.rs:615 names the variable double, but it also covers int32/uint32/int64/uint64 outputs. wide would be clearer. (high)
  • Nit, not posted: docs/python.md lines 197–201 are unwrapped and much longer than the surrounding text.

CLAUDE.md / AGENTS.md:

  • The change does not follow the rule that new options are exposed consistently across public surfaces. complex_dtype on Raster.from_array and out_dtype on Raster.read exist only in Python, and the PR does not say whether CLI or MCP should get them. Low confidence this is a violation, since the surfaces may not apply.
  • The validation evidence in the PR description predates the final two corrections (2ec26a22 and the r+ update path). The PR says those were not validated against a rebuilt native extension locally and rely on CI, so CI must be green before merge.
  • ROADMAP.md is still accurate. Its note that complex bands are excluded from terrio.rio's core reads still holds.

Test coverage:

  • python/tests/test_rio_complex_writer.py:579: test_precise_complex_copy_checks_wide_output_before_allocation accepts a refusal at any stage, so it cannot show the check happens before allocation. (medium)

Change size

Compared: the whole PR against main (merge base 433ed60 to PR head 2f07cdf).

Measure Value
Files changed 20 (added 2, modified 18, removed 0, renamed 0)
Size before 1.50 MB
Size after 1.55 MB
Total size change +53.2 KB

Largest changes by file size:

Path Before After Change
python/tests/test_rio_complex_writer.py 0 B 26.6 KB +26.6 KB
python/src/raster.rs 56.4 KB 63.8 KB +7.4 KB
python/python/terrio/rio/io.py 139.3 KB 145.2 KB +5.9 KB
crates/terrio/tests/geotiff_complex.rs 10.8 KB 14.0 KB +3.2 KB
docs/python.md 59.1 KB 61.1 KB +2.3 KB
js/tests/node.test.mjs 281.0 KB 282.7 KB +1.7 KB
scripts/conformance.py 202.0 KB 203.4 KB +1.4 KB
python/README.md 21.2 KB 22.5 KB +1.3 KB
scripts/tests/test_complex_writer_prerequisites.py 0 B 1.2 KB +1.2 KB
crates/terrio/src/pixel.rs 6.8 KB 7.7 KB +0.9 KB
docs/testing.md 193.7 KB 194.2 KB +0.5 KB
crates/terrio/src/ops/translate.rs 82.2 KB 82.7 KB +0.5 KB
python/python/terrio/rio/_boundless.py 32.6 KB 33.1 KB +0.5 KB
python/python/terrio/rio/shutil.py 11.5 KB 11.8 KB +0.4 KB
python/python/terrio/rio/vrt.py 66.9 KB 67.2 KB +0.3 KB
python/python/terrio/_terrio.pyi 82.3 KB 82.4 KB +0.1 KB
crates/terrio/src/drivers/gtiff_write.rs 234.2 KB 234.3 KB +0.1 KB
python/src/cog_writer.rs 6.7 KB 6.8 KB +0.1 KB
crates/terrio/src/lib.rs 18.7 KB 18.7 KB +0.0 KB
python/tests/test_synthetic.py 25.7 KB 25.6 KB −0.0 KB

@giswqs
giswqs merged commit f64365b into main Nov 12, 2026
24 checks passed
@giswqs
giswqs deleted the fix/complex-raster-writes branch November 12, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant