NetworkXError on incompatible key types after node label migration
0 reputation · 16 Sept 2026, 07:36 UTC
Upgrade failure with mixed node labels
After upgrading NetworkX, a Graph built with node labels of mixed types—such as strings and integers—can raise a NetworkXError when passed to functions that expect uniform hashable keys. The library documentation states that node labels must be hashable, yet earlier versions tolerated arbitrary Python objects, leaving behavior inconsistent across releases.
Version 2.5 also changed the internal node attribute storage from a plain dict to a custom mapping. Code that manipulated G.nodes or node attribute dictionaries directly may break because the underlying container is no longer a standard dict. No deprecation path or migration script accompanied this change.
Because the upgrade path is not clearly defined, safe recovery is uncertain. There is no standardized way to verify that a migrated graph preserves both structure and attribute access semantics, leaving users to decide whether to normalize labels before upgrading or refactor code that relies on direct dict operations.
What is the supported strategy for migrating a NetworkX graph with mixed node label types to a newer version without triggering the incompatible key type error? How should code that directly accesses the node attribute dictionary be adjusted for the custom mapping introduced in version 2.5? Is there an official migration guide or compatibility layer for projects that cannot immediately refactor direct dict access?