-
Notifications
You must be signed in to change notification settings - Fork 2
Vectorize continuous color computation in pl.nodes() for large speedup #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,7 +365,10 @@ def _get_colors( | |
| if data.dtype.kind in ["i", "f"]: # Numeric | ||
| norm = _get_norm(vmin=vmin, vmax=vmax, data=data) | ||
| color_map = plt.get_cmap(cmap) | ||
| colors = [color_map(norm(data[i])) if i in data.index else na_color for i in indicies] | ||
| # Vectorized: reindex to align with indicies (NaN for missing), then apply colormap in bulk | ||
| values = data.reindex(indicies) | ||
| color_map.set_bad(na_color) | ||
| colors = color_map(norm(np.ma.masked_invalid(values.values.astype(float)))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using Useful? React with 👍 / 👎. |
||
| legend = _cbar_legend(key, color_map, norm) | ||
| n_categories = 0 | ||
| else: # Categorical | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
np.ma.masked_invalid(...)here masks bothNaNand±inf, so any infinite numeric values are now rendered withna_colorinstead of being mapped through the continuous colormap. This changes result semantics for workflows where overflow/div-by-zero values appear in node/edge metrics (they become visually indistinguishable from truly missing values), whereas the previous per-element path only treated absent indices as missing.Useful? React with 👍 / 👎.