Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
- Dropped support for Python 3.9 and 3.10 as they have reached their end of
life. The minimum supported Python version is now 3.11.

### Removed

- Removed the undocumented `warnings` argument of `Graph.topological_sorting()`.
It had no effect since igraph 0.9, where topological sorting started
raising an error instead of a warning for graphs with cycles.

### Fixed

- Errors raised while converting a boolean argument to a boolean (e.g. when
Expand All @@ -30,6 +24,16 @@
- `Graph.assortativity_nominal()` raised a `SystemError` whenever the `weights`
argument was given, because the argument was not parsed.

- Attribute combination (e.g. in `Graph.simplify()` or
`Graph.contract_vertices()`) no longer fails with an internal error when an
attribute name contains non-ASCII characters.

### Removed

- Removed the undocumented `warnings` argument of `Graph.topological_sorting()`.
It had no effect since igraph 0.9, where topological sorting started
raising an error instead of a warning for graphs with cycles.

## 1.0.1 - 2025-12-26

### Changed
Expand Down
23 changes: 19 additions & 4 deletions src/_igraph/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int igraphmodule_PyObject_matches_attribute_record(PyObject* object, igraph_attr
}

if (PyUnicode_Check(object)) {
return PyUnicode_IsEqualToASCIIString(object, record->name);
return igraphmodule_PyUnicode_IsEqualToUTF8String(object, record->name);
}

return 0;
Expand Down Expand Up @@ -521,6 +521,7 @@ static igraph_error_t igraphmodule_i_attribute_add_vertices(
/* Extend the end of every value in the vertex hash with nv pieces of None */
PyObject *key, *value, *dict;
igraph_int_t i, j, k, num_attr_entries;
int match;
igraph_attribute_record_t *attr_rec;
igraph_vector_bool_t added_attrs;
Py_ssize_t pos = 0;
Expand Down Expand Up @@ -550,7 +551,11 @@ static igraph_error_t igraphmodule_i_attribute_add_vertices(
attr_rec = NULL;
for (i = 0; i < num_attr_entries; i++) {
attr_rec = igraph_attribute_record_list_get_ptr(attr, i);
if (igraphmodule_PyObject_matches_attribute_record(key, attr_rec)) {
match = igraphmodule_PyObject_matches_attribute_record(key, attr_rec);
if (match < 0) {
IGRAPH_ERROR("Cannot compare vertex attribute names.", IGRAPH_FAILURE);
}
if (match) {
VECTOR(added_attrs)[i] = 1;
break;
}
Expand Down Expand Up @@ -746,6 +751,7 @@ static igraph_error_t igraphmodule_i_attribute_add_edges(
PyObject *key, *value, *dict;
Py_ssize_t pos = 0;
igraph_int_t i, j, k, ne, num_attr_entries;
int match;
igraph_vector_bool_t added_attrs;
igraph_attribute_record_t *attr_rec;

Expand Down Expand Up @@ -775,7 +781,11 @@ static igraph_error_t igraphmodule_i_attribute_add_edges(
attr_rec = NULL;
for (i = 0; i < num_attr_entries; i++) {
attr_rec = igraph_attribute_record_list_get_ptr(attr, i);
if (igraphmodule_PyObject_matches_attribute_record(key, attr_rec)) {
match = igraphmodule_PyObject_matches_attribute_record(key, attr_rec);
if (match < 0) {
IGRAPH_ERROR("Cannot compare edge attribute names.", IGRAPH_FAILURE);
}
if (match) {
VECTOR(added_attrs)[i] = 1;
break;
}
Expand Down Expand Up @@ -1400,6 +1410,7 @@ static igraph_error_t igraphmodule_i_attribute_combine_dicts(PyObject *dict,
Py_ssize_t pos;
igraph_attribute_combination_record_t* todo;
Py_ssize_t i, n;
int match;

if (!PyDict_Check(dict) || !PyDict_Check(newdict)) {
IGRAPH_ERROR("dict or newdict are corrupted", IGRAPH_FAILURE);
Expand Down Expand Up @@ -1438,7 +1449,11 @@ static igraph_error_t igraphmodule_i_attribute_combine_dicts(PyObject *dict,
PyObject *newvalue;

/* Safety check */
if (!PyUnicode_IsEqualToASCIIString(key, todo[i].name)) {
match = igraphmodule_PyUnicode_IsEqualToUTF8String(key, todo[i].name);
if (match < 0) {
IGRAPH_ERROR("Cannot compare attribute names.", IGRAPH_FAILURE);
}
if (!match) {
IGRAPH_ERROR("PyDict_Next iteration order not consistent. "
"This should never happen. Please report the bug to the igraph "
"developers!", IGRAPH_FAILURE);
Expand Down
13 changes: 12 additions & 1 deletion src/_igraph/pyhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ char* igraphmodule_PyUnicode_CopyAsString(PyObject* string) {
return result;
}

/**
* Checks whether a Python string is equal to a UTF-8 encoded C string.
*
* Returns 1 if they are equal, 0 if they are not (or if the Python object is
* not a string), and -1 with a Python exception set if the C string could not
* be converted to a Python string.
*
* Do not use the result directly as a boolean, as in
* if (igraphmodule_PyUnicode_IsEqualToUTF8String(...)) { ... }; the error
* value -1 would then count as a match. Check for a negative result first.
*/
int igraphmodule_PyUnicode_IsEqualToUTF8String(PyObject* py_string,
const char* c_string) {
PyObject* c_string_conv;
Expand All @@ -205,7 +216,7 @@ int igraphmodule_PyUnicode_IsEqualToUTF8String(PyObject* py_string,

c_string_conv = PyUnicode_FromString(c_string);
if (c_string_conv == 0)
return 0;
return -1;

result = (PyUnicode_Compare(py_string, c_string_conv) == 0);
Py_DECREF(c_string_conv);
Expand Down
15 changes: 15 additions & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def testCombinationConcat(self):
self.assertFalse("weight2" in g.edge_attributes())
self.assertTrue(g.es["name"] == ["AB", "C", "DEF"])

def testCombinationNonASCIIName(self):
# Attribute names are passed to the C core as UTF-8, so the names
# must be compared as UTF-8 and not as ASCII.
g = self.g
name = "caf\u00e9"
g.es[name] = [1, 2, 3, 4, 5, 6, 7]
g.simplify(combine_edges={name: "sum", None: "ignore"})
self.assertEqual(g.edge_attributes(), [name])
self.assertEqual(g.es[name], [3, 3, 15])

g = Graph.Ring(4)
g.vs[name] = [1, 2, 3, 4]
g.contract_vertices([0, 0, 1, 1], combine_attrs="sum")
self.assertEqual(g.vs[name], [3, 7])

def testCombinationMaxMinIgnore(self):
g = self.g
g.es["name"] = list("ABCDEFG")
Expand Down
Loading