Repository navigation
fix: compare complex real and imaginary components separately in _array_all_equal - #4688
Open
ApacheWang wants to merge 2 commits into
Open
ApacheWang wants to merge 2 commits into
ApacheWang wants to merge 2 commits into
Conversation
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
This branch has not been deployed
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
Fix
_array_all_equal()insrc/zarr/core/buffer/core.pyso complex arrays compared withequal_nan=Truecompare their real and imaginary components separately instead of treating any complex value containing aNaNcomponent as equal.Root Cause
fill_value(NDBuffer.all_equal(..., equal_nan=True)),_array_all_equaldelegates directly tonp.array_equal(_data, other, equal_nan=True)(src/zarr/core/buffer/core.py:575).np.array_equalwithequal_nan=Truetreats any complex number where either the real or imaginary component isNaNas equal to any other complex number with aNaNcomponent (socomplex(nan, 7)andcomplex(0, nan)compare equal tocomplex(nan, 0)).nan + 7jor0 + nanjinto a chunk whosefill_valueisnan + 0jcausesall_equalto returnTrue, silently dropping the chunk as fill-only.Changes
equal_nanisTrueand_data.dtype.kind == "c", check bothnp.array_equal(_data.real, other.real, equal_nan=True)andnp.array_equal(_data.imag, other.imag, equal_nan=True).test_all_equal_compares_complex_nan_componentsintests/test_buffer.pycovering(nan+0j, nan+7j),(0+nanj, 7+nanj), and(nan+0j, 0+nanj).Verification
7612281):test_all_equal_compares_complex_nan_componentsfails on all 3 cases (3 failed) becauseall_equalwrongly returnsTruefor differing finite/NaN components.test_all_equalcases intests/test_buffer.pypass (1806 passed).ruff check,ruff format --check, andgit diff --checkpass cleanly on both modified files.