Repository navigation
Conversation
Select complex dimension and I/O handling using the variable dtype, preserving automatic complex decoding on reopen. Fixes Unidata#1404. Assisted-by: Codex
|
@ZedThree could you review this? |
|
@FFspiky this needs a Changelog entry |
|
@jswhit Added the entry under the unreleased 1.7.6 section in 56ca59b. This follow-up only changes I also checked the two failing jobs from the previous revision:
The new workflows are waiting for approval again, including Build and Test and Wheels. Could you approve them when convenient? |
ZedThree
left a comment
There was a problem hiding this comment.
This took me a minute to understand, but I think I understand now. We can use dtype_is_complex(self.dtype) in these places because we have already checked if auto_complex == True by then. So then this call can only be true if we have an actual complex dtype and we're using auto_complex.
Thanks @FFspiky!
With
auto_complex=True, creating an explicitly real variable over a length-twocomplexdimension currently hides that dimension while retaining the real dtype. Writing a matching real array then fails with a reshape/broadcast error.Use the variable's Python dtype to select complex rank, dimension and I/O handling. Explicitly created real and compound variables retain their requested dimensions and storage types. Reopening a supported complex layout with
auto_complex=Truestill produces the complex dtype and hides its component axis. Document this creation/reopening distinction.Fixes #1404.
Regression coverage includes the three component-dimension names, f4/f8/i4 storage, contiguous/strided/reversed reads and writes, NETCDF4/NETCDF4_CLASSIC/NETCDF3_CLASSIC real storage, actual compound/dimension complex storage at c8/c16 precision, casts from real input, and reopening for complex reads and writes.
Validation on macOS arm64, Python 3.12.14, NumPy 2.5.4, netcdf-c 4.9.3 and HDF5 1.14.6, using a native editable build of the changed source:
pytest test/test_complex.py -q: 9 passed, 33 subtests passed.pytest test --ignore=test/test_dap.py -q: 160 passed, 1 skipped, 1 xpassed, 11,288 subtests passed. The xpass is the existing blosc-marked case.git diff --checkpassed.OPeNDAP, MPI, other platforms and native sanitizers were not run locally. Existing NETCDF4_CLASSIC complex creation and other native convention-detection limitations are outside this fix.
AI assistance: OpenAI Codex implemented the patch and tests, built and tested the native extension, and drafted this description.