Skip to content

Fix several invalid weight argument handling bugs - #900

Draft
szhorvat wants to merge 3 commits into
igraph:mainfrom
szhorvat:fix/numeric-arg-validation
Draft

szhorvat wants to merge 3 commits into
igraph:mainfrom
szhorvat:fix/numeric-arg-validation

Conversation

@szhorvat

Copy link
Copy Markdown
Member

No description provided.

igraphmodule_PyObject_to_attribute_values(), used for the weights of
pagerank(), personalized_pagerank() and constraint() and for the
capacities of the flow and cut functions, replaced every list item that
was not an int or float with 1, and treated any sequence other than a
list as an attribute name. As a result, pagerank(weights=["a", "b"])
silently returned unweighted results, while strength() raised
ValueError for the same input. Large integers overflowed with a
pending exception.

It now delegates to igraphmodule_attrib_to_vector_t(), like most other
functions that take weights: non-numeric values in a sequence or an
attribute raise ValueError, and any sequence (tuples, NumPy arrays) is
accepted. Missing (None) attribute values are now rejected too, instead
of being replaced by 1.

Unknown attribute names given to weight-like arguments now raise
KeyError in all functions. Previously the flow functions raised
KeyError, while the others raised InternalError.

Assisted-by: Claude Opus 5.5
Graph.Chung_Lu(), Graph.Establishment(), Graph.layout_umap() and
umap_compute_weights() converted their real-valued vector arguments
(vertex weights, type distribution, distances and edge weights) with
the integer conversion function, silently truncating every value.
For example, Graph.Chung_Lu([0.9] * 1000) always returned a graph
without edges, and Graph.Establishment() rejected [0.3, 0.7] as a type
distribution.

The expected values of the umap_compute_weights() test were computed
from the truncated distances and are updated.

Negative values are now reported by the C core instead of the Python
interface.

Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
@szhorvat
szhorvat force-pushed the fix/numeric-arg-validation branch from 93ac1c6 to 46dc1a6 Compare November 29, 2026 22:15
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.

1 participant