Allow concatenation of string coordinates of differing width (#6676)#7125
Open
gaoflow wants to merge 1 commit into
Open
Allow concatenation of string coordinates of differing width (#6676)#7125gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Concatenation compared coordinate dtypes exactly, so two cubes whose string coordinate differed only in width (e.g. '<U1' vs '<U5') were reported as having differing metadata and could not be concatenated. When comparing the coordinate signatures, collapse string dtypes to their kind so differing widths no longer block concatenation; numpy promotes the points to a common width when they are joined. Genuine dtype-kind differences (e.g. string vs integer) are still rejected. Fixes SciTools#6676.
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.
🚀 Pull Request
Description
Closes #6676.
Two cubes whose string coordinate differs only in width (i.e. dtype, such as
<U1vs<U5) could not be concatenated:Cause
When building the coordinate signature,
_CoordMetaDatarecords each coordinate'spoints_dtype/bounds_dtype, and__eq__compares them exactly. For string coordinates,<U1and<U5are different dtypes, so the metadata was reported as differing even though the coordinates are otherwise compatible.Fix
When comparing coordinate signatures, collapse string dtypes (kind
"U"/"S") to their kind, so that differing widths no longer block concatenation. numpy promotes the points to a common width when they are joined, so the result coordinate gets the wider dtype (<U5above). Genuine dtype-kind differences (e.g. string vs integer) are unaffected and still rejected.Verification
TestStringAuxCoordWidths:test_different_widths— the two cubes above now concatenate; the result coordinate has dtype<U5and the expected points. Fails onmain, passes here.test_different_dtype_kind_still_rejected— string-vs-integer coordinates still raiseConcatenateError.tests/unit/concatenate/,tests/integration/concatenate/andtests/test_concatenate.pysuites pass (283 + 54 tests).ruff check/ruff formatclean.