Skip to content
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

AttributeError: module 'numpy' has no attribute 'NAN'. Did you mean: 'nan'? #21

Closed
aekiss opened this issue Jan 14, 2025 · 7 comments
Closed

Comments

@aekiss
Copy link

aekiss commented Jan 14, 2025

When running cice_from_mom to fix COSIMA/access-om3#252 I get

+ cice_from_mom --ocean_hgrid ocean_hgrid.nc --ocean_mask ocean_mask.nc
Traceback (most recent call last):
  File "/g/data/tm70/aek156/domain-tools/C-grid-workflow/fill_fraction_0.5_AK/.venv/bin/cice_from_mom", line 8, in <module>
    sys.exit(cice_from_mom())
  File "/g/data/tm70/aek156/domain-tools/C-grid-workflow/fill_fraction_0.5_AK/.venv/lib/python3.10/site-packages/esmgrids/cli.py", line 42, in cice_from_mom
    mom = MomGrid.fromfile(ocean_hgrid, mask_file=ocean_mask)
  File "/g/data/tm70/aek156/domain-tools/C-grid-workflow/fill_fraction_0.5_AK/.venv/lib/python3.10/site-packages/esmgrids/mom_grid.py", line 106, in fromfile
    clat_t, clon_t, clat_u, clon_u, _, _ = make_corners(x, y)
  File "/g/data/tm70/aek156/domain-tools/C-grid-workflow/fill_fraction_0.5_AK/.venv/lib/python3.10/site-packages/esmgrids/mom_grid.py", line 176, in make_corners
    clon_t[:] = np.NAN
  File "/g/data/tm70/aek156/domain-tools/C-grid-workflow/fill_fraction_0.5_AK/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 414, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'NAN'. Did you mean: 'nan'?

see esmgrids/mom_grid.py#L176.

Is np.NAN an alias of np.nan that's only available in some versions of numpy? ie should we use np.nan throughout the code instead?

@anton-seaice
Copy link
Contributor

hmm - thats odd. Do you have permissions to trigger the tests manually ? e.g. at https://github.com/COSIMA/esmgrids/actions/workflows/ci.yml ?

@minghangli-uni
Copy link

I've never used np.NAN before. Not sure how it might have worked previously.

@anton-seaice
Copy link
Contributor

It looks like np.NAN was deprecated with numpy 2.0 (released mid 2024).

Specifying "numpy ==1.26.4" in pyproject.toml works as expected, and is maybe safer option than updated the esmgrids code in haste.

@aekiss
Copy link
Author

aekiss commented Jan 15, 2025

changing np.NAN to np.nan throughout the code fixed my issue and is a more future-proof solution if np.NAN is equivalent to np.nan in numpy <2.0

@anton-seaice
Copy link
Contributor

Yeah good - I just wasn't sure if their could be other unexpected differences with numpy 2 !

@aekiss
Copy link
Author

aekiss commented Jan 15, 2025

I'll open a PR

@anton-seaice
Copy link
Contributor

This was closed through #23

We decided to revert to numpy 1 as the ocean_model_grid_generator test dependency also didn't work with numpy 2. I raised an issue on that repo see ACCESS-NRI/ocean_model_grid_generator#2

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 a pull request may close this issue.

3 participants