Skip to content

Replace np.NaN with np.nan for numpy 2.x compatibility#156

Merged
bendichter merged 1 commit into
masterfrom
fix-numpy2-np-nan
May 13, 2026
Merged

Replace np.NaN with np.nan for numpy 2.x compatibility#156
bendichter merged 1 commit into
masterfrom
fix-numpy2-np-nan

Conversation

@bendichter
Copy link
Copy Markdown
Member

NumPy 2.0 removed the deprecated capitalized alias np.NaN in favor of np.nan (the canonical lowercase form, which has always existed). Searching the repo:

  • np.NaN: 1 notebook — 000559/dattalab/markowitz_gillis_nature_2023/reproduce_figure1d.ipynb (one usage)
  • np.NAN, np.Inf, np.product, np.cumproduct, np.sometrue, np.alltrue, np.float_, np.complex_, np.unicode_, np.cast: none in .ipynb files outside the (already-excluded) DataJoint subdirs.

This PR converts the single occurrence:

- vel_angle[np.abs(vel_angle) > 100] = np.NaN  # remove artifacts
+ vel_angle[np.abs(vel_angle) > 100] = np.nan  # remove artifacts

That was the only thing keeping this notebook pinned to numpy<2 in #149's lockfile (the resolver dropped numpy from the Colab constraint set for this one because np.NaN is gone in numpy 2.x). After this lands, the next regen on #149 will pick up numpy==2.0.2 for this notebook, matching Colab — and Colab users won't need to restart the runtime on install.

Notebooks NOT touched (and why)

Two other notebooks were also pinned to numpy<2 in #149's locks, but for unrelated reasons — they don't use any removed numpy APIs:

  • 000559/.../reproduce_figure_S1.ipynb — pinned because of cellpose<4 (cellpose 4.x dropped the old Cellpose class the notebook uses). The numpy<2 is a transitive consequence of cellpose's deps, not a notebook-content issue.
  • 000582/Sargolini2006/000582_Sargolini2006_demo.ipynb — pinned via pynapple>=0.6 transitive deps. Notebook code is numpy-2.x clean.

Those two would need different fixes (cellpose modernization / pynapple version bump) and are out of scope here.

The diff also includes nbformat-added cell id fields on a few previously-id-less cells — that's an automatic normalization on save, not a content change.

🤖 Generated with Claude Code

NumPy 2.0 removed `np.NaN` (the deprecated capitalized alias) in
favor of `np.nan` (the canonical lowercase form, which always
existed). This notebook had one usage:

    vel_angle[np.abs(vel_angle) > 100] = np.NaN  # remove artifacts

This was the only thing keeping the file pinned to `numpy<2` — with
this fix, the notebook works against the current Colab runtime's
`numpy==2.0.2` without needing a kernel restart on install.

(Auto-added cell IDs in the same diff are an nbformat-write
normalization, not a content change.)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@bendichter bendichter merged commit b3fe060 into master May 13, 2026
3 of 4 checks passed
github-actions Bot added a commit that referenced this pull request May 13, 2026
github-actions Bot added a commit that referenced this pull request May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Preview for this PR has been removed (PR closed).

bendichter added a commit to catalystneuro/example-notebooks that referenced this pull request May 14, 2026
…i#156)

The lock generated by PR dandi#159 pinned `numpy==1.26.4` because the
PR-141-era input deps included `numpy>=1.26,<2`. That cap was there
because the notebook used `np.NaN` (removed in numpy 2.0). PR dandi#156
already replaced `np.NaN` with `np.nan`, so the cap is now stale
and the notebook code is numpy-2.x clean.

Re-resolved with `numpy>=1.26` (no upper cap) against the Colab
constraints set. The only line that changed is the numpy pin —
everything else was already at Colab versions:

  numpy   1.26.4 -> 2.0.2  (matches Colab — no restart on install)

Now the install on Colab is fully no-op for numpy/pandas/scipy/h5py/etc.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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