Skip to content

Conversation

@Thijss
Copy link
Member

@Thijss Thijss commented May 8, 2025

Found was an issue where the graph.external_ids would change type if the input to graph.tmp_remove_nodes is an ndarray[int[ instead of a list[int]

While a type-checker should prevent you from doing this. It is not enforced at runtime.
This PR prevents the type change by explicitly casting the ids to integers before re-adding them to the graph.

Example:

    with graph.tmp_remove_nodes(np.array([1, 2])): 
        pass
# would previously result in graph.external_ids to contain np.int values instead of int values

@Thijss Thijss changed the title Fix: prevent type change in graph.external_ids when using tmp_remove_… Fix: prevent type change when using tmp_remove_nodes May 8, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 8, 2025

@Thijss
Copy link
Member Author

Thijss commented May 8, 2025

Open question: should we change the type signature of def tmp_remove_nodes(self, nodes: list[int]) -> Generator: to also allow ndarray[int]?
I opted for no so far since we previously settled on keeping everything list[int] within the Graph class

Copy link
Member

@jaapschoutenalliander jaapschoutenalliander left a comment

Choose a reason for hiding this comment

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

Well found. On the typing, I think it's cleaner to keep that as it is and just see support for other iterables as a bonus

@Thijss Thijss merged commit d2bc1f1 into main May 9, 2025
19 checks passed
@Thijss Thijss deleted the fix/prevent-type-change branch May 9, 2025 08:05
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