GAA-UAM / scikit-fda

Functional Data Analysis Python package
https://fda.readthedocs.io
BSD 3-Clause "New" or "Revised" License
297 stars 53 forks source link

ImportError: cannot import name 'invert_warping' from 'skfda._utils' #623

Closed jnahlers closed 2 weeks ago

jnahlers commented 1 month ago

Bug description summary

I am trying to follow the example for least squares registration . I am in a fresh conda environment (python=3.10), and have installed scikit-fda from PyPi: pip install scikit-fda (installs scikit-fda-0.9.1).

When I try and import the registration, I get an import error: ImportError: cannot import name 'invert_warping' from 'skfda._utils'

I have also tried installing the conda version instead, and get the same error. conda install -c conda-forge scikit-fda

Code to reproduce the bug

from skfda.preprocessing import registration

Expected result

I would expect it to import 😄

Actual result

It doesn't import 😢

Traceback (if an exception is raised)

>>> from skfda.preprocessing import registration
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\username\Anaconda3\envs\test\lib\site-packages\lazy_loader\__init__.py", line 79, in __getattr__
    return importlib.import_module(f"{package_name}.{name}")
  File "C:\Users\username\Anaconda3\envs\test\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\username\Anaconda3\envs\test\lib\site-packages\skfda\preprocessing\registration\__init__.py", line 10, in <module>
    from ..._utils import (
ImportError: cannot import name 'invert_warping' from 'skfda._utils' (C:\Users\username\Anaconda3\envs\test\lib\site-packages\skfda\_utils\__init__.py)

Software versions

scikit-fda version: 0.9.1

Additional context

No response

jnahlers commented 1 month ago

Tested on Windows 10 and Rocky Linux 9.2. Both throw the exception.

jnahlers commented 1 month ago

Some more info: I tried fresh conda envs with python=3.9. Using pip install scikit-fda I still get the exception coming up, but using conda install -c conda-forge scikit-fda the import worked fine.

I would love to hear if this is reproducible, I feel like I might be running into some weird python/conda misconfiguration bug.

tomas-ramos21 commented 3 weeks ago

I'm getting a similar error to the one mentioned in this issue when I try to import the library. The code causing it is provided below:

>>> from skfda import FDataGrid
Traceback (most recent call last):
  File "/Users/username/Repos/FNNs/model.py", line 3, in <module>
    from skfda import FDataGrid
  File "/Users/username/.pyenv/versions/FNNs/lib/python3.9/site-packages/lazy_loader/__init__.py", line 83, in __getattr__
    attr = getattr(submod, name)
  File "/Users/username/.pyenv/versions/FNNs/lib/python3.9/site-packages/lazy_loader/__init__.py", line 82, in __getattr__
    submod = importlib.import_module(submod_path)
  File "/Users/username/.pyenv/versions/3.9.19/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/username/.pyenv/versions/FNNs/lib/python3.9/site-packages/skfda/representation/grid.py", line 33, in <module>
    from .._utils import _check_array_key, _int_to_real, _to_grid_points, constants
ImportError: cannot import name '_check_array_key' from 'skfda._utils' (/Users/username/.pyenv/versions/FNNs/lib/python3.9/site-packages/skfda/_utils/__init__.py)

I installed scikit-fda in a clean environment using Python 3.9.19.

tomas-ramos21 commented 3 weeks ago

@jnahlers It seems to be a compatibility issue between scikit-fda and the latest version of scikit-learn. I was able to import the package by installing an older version (1.4.0) of scikit-learn. Like so: pip install scikit-learn==1.4.0

vnmabus commented 2 weeks ago

Note that the current development version only works with Python 3.10 onward. Support for Python 3.9 has been dropped as per SPEC0, which is followed by all major scientific packages. Support for Python 3.10 will be dropped at the end of 2024.

Thus, no fixes for Python 3.9 integration with newer packages are planned. I encourage you to upgrade your Python version if you can, and to follow SPEC0 to be aware of the deprecations of particular versions of scientific packages and be able to plan ahead.

I will release a new version as soon as I can merge some recent improvements. In the meantime, it should be possible to install the development version directly from git (for Python >= 3.10):

python -m pip install git+https://github.com/GAA-UAM/scikit-fda.git@develop

As this error refers to Python 3.9 and I have not been able to reproduce it in the current development version (I tested it under Python 3.11), I will close this issue. Please, feel free to reopen the issue if the error remains when upgrading to the latest version.

jnahlers commented 2 weeks ago

Note that the current development version only works with Python 3.10 onward. Support for Python 3.9 has been dropped as per SPEC0, which is followed by all major scientific packages. Support for Python 3.10 will be dropped at the end of 2024.

Thanks Carlos! Just a note - the original bug report was for Python 3.10. I also just tried a fresh install on 3.11 and had the same issue (when installing from PyPi). However, when I made another fresh 3.11 env and installed the github development version instead, I had no issue.