Skip to content

fix: compare attribute names as UTF-8 during attribute combination - #897

Merged
ntamas merged 2 commits into
igraph:mainfrom
szhorvat:fix/utf8-attribute-names
Nov 29, 2026
Merged

ntamas merged 2 commits into
igraph:mainfrom
szhorvat:fix/utf8-attribute-names

Conversation

@szhorvat

Copy link
Copy Markdown
Member

Attribute names are passed to the C core as UTF-8, but they were compared against the Python keys with PyUnicode_IsEqualToASCIIString(). For a non-ASCII name the comparison always failed, so
Graph.simplify() and Graph.contract_vertices() raised an InternalError when combining attributes. Use igraphmodule_PyUnicode_IsEqualToUTF8String() instead, both in the combination loop and when matching attribute records.

Assisted-by: Claude Opus 5.5

@szhorvat
szhorvat requested review from ntamas and a balanced review from Copilot November 28, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the non-ASCII attribute-name handling fix.

No open issues 🎉

What changed in this PR

This PR fixes non-ASCII attribute-name handling in the Python-to-C interface so attribute combination works in Graph.simplify() and Graph.contract_vertices().

Changes:

  • Use UTF-8-aware comparisons when matching attribute records and combining attributes.
  • Add regression coverage for non-ASCII edge and vertex attribute names.
  • Document the fix in the changelog.
File Description
tests/​test_attributes.py Tests combining non-ASCII attributes during simplification and vertex contraction.
src/​_igraph/​attributes.c Replaces two ASCII comparisons with UTF-8-aware comparisons.
CHANGELOG.md Documents the non-ASCII attribute-combination fix.

Review effort: Balanced

@szhorvat
szhorvat marked this pull request as draft November 28, 2026 15:17
Attribute names are passed to the C core as UTF-8, but they were compared
against the Python keys with PyUnicode_IsEqualToASCIIString(). For a
non-ASCII name the comparison always failed, so Graph.simplify() and
Graph.contract_vertices() raised an InternalError when combining
attributes, and adding vertices or edges with attribute values from the
C core could overwrite the existing values of such an attribute.

Use igraphmodule_PyUnicode_IsEqualToUTF8String() instead, both in the
combination loop and when matching attribute records. Since that helper
allocates a temporary Python string, make it return -1 with a Python
exception set on failure, and raise an igraph error in all callers
instead of treating the failure as a mismatch.

Assisted-by: Claude Opus 5.5
@szhorvat
szhorvat force-pushed the fix/utf8-attribute-names branch from 45aa681 to f33e337 Compare November 28, 2026 15:24
@szhorvat
szhorvat marked this pull request as ready for review November 28, 2026 15:51
@ntamas
ntamas merged commit 6789c19 into igraph:main Nov 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants