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

Problem when importing pynldas2: No module named 'numpy.core._exceptions' #9

Closed
LucRSquared opened this issue Jul 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@LucRSquared
Copy link
Contributor

LucRSquared commented Jul 2, 2024

What happened?

I don't know exactly why I am encountering this bug as I was using the module fine up to a few days ago, maybe there was a NumPy update. I currently have the version 2.0.0 installed.

I tried this in a fresh virtual environment with only pynldas2 installed with pip

If I import pynldas2 I get the following error message:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[12], [line 1](vscode-notebook-cell:?execution_count=12&line=1)
----> [1](vscode-notebook-cell:?execution_count=12&line=1) import pynldas2

File c:\Users\Luc\projects\pyagnps\.venv\Lib\site-packages\pynldas2\__init__.py:6
      [4](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/__init__.py:4) from pynldas2.exceptions import InputRangeError, InputTypeError, InputValueError, NLDASServiceError
      [5](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/__init__.py:5) from pynldas2.print_versions import show_versions
----> [6](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/__init__.py:6) from pynldas2.pynldas2 import get_bycoords, get_bygeom, get_grid_mask
      [8](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/__init__.py:8) try:
      [9](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/__init__.py:9)     __version__ = version("pynldas2")

File c:\Users\Luc\projects\pyagnps\.venv\Lib\site-packages\pynldas2\pynldas2.py:16
     [14](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/pynldas2.py:14) import pyproj
     [15](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/pynldas2.py:15) import xarray as xr
---> [16](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/pynldas2.py:16) from numpy.core._exceptions import UFuncTypeError
     [17](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/pynldas2.py:17) from pandas.errors import EmptyDataError
     [19](file:///C:/Users/Luc/projects/pyagnps/.venv/Lib/site-packages/pynldas2/pynldas2.py:19) import async_retriever as ar

ModuleNotFoundError: No module named 'numpy.core._exceptions'

Line 16 of pynldas2.py tries to import a class which results in the error above:

from numpy.core._exceptions import UFuncTypeError

I went and checked and this class is indeed present under numpy -> core -> _exceptions.py so there must be a mechanism preventing the import.

I do believe I know what would fix it: If just run

numpy.core._exceptions

I get a DeprecationWarning:

DeprecationWarning: numpy.core is deprecated and has been renamed to numpy._core. The numpy._core namespace contains private NumPy internals and its use is discouraged, as NumPy internals can change without warning in any release. In practice, most real-world usage of numpy.core is to access functionality in the public NumPy API. If that is the case, use the public NumPy API. If not, you are using NumPy internals. If you would still like to access an internal attribute, use numpy._core._exceptions.
  numpy.core._exceptions

Thus this works without any issue:

from numpy._core._exceptions import UFuncTypeError

So adding a leading underscore in front of core would solve the issue.

Minimal Complete Verifiable Example

python -c "import pynldas2"

Environment

Fresh virtual environment with Python 3.11

@LucRSquared LucRSquared added the bug Something isn't working label Jul 2, 2024
@cheginit
Copy link
Contributor

cheginit commented Jul 2, 2024

Thanks for reporting the issue.

Yes, it's a numpy 2 compatibility issue that I've already addressed, but still haven't released a new version. So, if you update from git, it should work fine. I will release an update soon.

@cheginit
Copy link
Contributor

cheginit commented Jul 8, 2024

This is fixed in v0.17.0. Please test it out and reopen if it's not fixed.

@cheginit cheginit closed this as completed Jul 8, 2024
@LucRSquared
Copy link
Contributor Author

This is fixed in v0.17.0. Please test it out and reopen if it's not fixed.

Just tested it, it works now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants