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

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

Open
jnahlers opened this issue Jul 17, 2024 · 8 comments
Open
Labels

Comments

@jnahlers
Copy link

jnahlers commented Jul 17, 2024

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 jnahlers added the bug label Jul 17, 2024
@jnahlers
Copy link
Author

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

@jnahlers
Copy link
Author

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
Copy link

tomas-ramos21 commented Aug 17, 2024

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
Copy link

@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
Copy link
Member

vnmabus commented Aug 20, 2024

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.

@vnmabus vnmabus closed this as completed Aug 20, 2024
@jnahlers
Copy link
Author

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.

@jnahlers
Copy link
Author

I am still getting this error in Python 3.11, but downgrading scikit-learn to scikit-learn==1.4.0 as suggested by @tomas-ramos21 seems to have fixed the issue. Suggest reopening, but I don't have permission to do so.

@vnmabus
Copy link
Member

vnmabus commented Jan 20, 2025

@jnahlers I will reopen the issue for now, until I have time to investigate.

@vnmabus vnmabus reopened this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants