raphaelvallat / yasa

YASA (Yet Another Spindle Algorithm): a Python package to analyze polysomnographic sleep recordings.
https://raphaelvallat.com/yasa/
BSD 3-Clause "New" or "Revised" License
429 stars 115 forks source link

YASA 0.6.3 issue #131

Closed sjg2203 closed 11 months ago

sjg2203 commented 1 year ago

Brilliant job you have done, tremendous contribution to the field! Though, I just noticed that with version 0.6.3, I had to downgrade Matplotlib from 3.6.2 to 3.6.0 on my intel Windows and both my intel and ARM macs and that I couldn't update some packages such as Charset-normaliser 2.1.1 (now 3.0.1) and NumPy 1.23.5 (now 1.24.1) otherwise YASA would not generate a plot nor work as intended

raphaelvallat commented 1 year ago

Thanks @sjg2203 ! Can you please provide more details? What error did you get when trying to plot? Which YASA function(s) were you using? Did you get a warning when upgrading yasa with pip?

It's the first time that I hear about charset-normaliser so I'm not sure how this can be related to YASA though.

sjg2203 commented 1 year ago

I am using those functions:

yasa.SleepStaging()
yasa.hypno_str_to_int()
sls.predict()
yasa.plot_hypnogram()
yasa.hypno_upsample_to_data()

At first it was not possible to update yasa through pip, I had to downgrade Matplotlib and Numpy to be able to do such. When running pipdeptree -p yasa, it returns this long list of all the dependencies (see below). But those two are somehow creating a bug and I had to downgrade Matplotlib 3.6.2 to 3.6.0 and Numpy 1.24.1 to 1.23.5 (as 1.24.0 was also creating a bug).

    - numpy [required: >=1.18,<1.24, installed: 1.23.5]
    - matplotlib [required: >=3.1,!=3.6.1, installed: 3.6.0]

Somehow charset_normalizer is working, except that it prints a warning that the user is using this version at his own risk. Dependendies list:

yasa==0.6.3
  - antropy [required: Any, installed: 0.1.5]
    - numba [required: Any, installed: 0.56.3]
      - llvmlite [required: >=0.39.0dev0,<0.40, installed: 0.39.1]
      - numpy [required: >=1.18,<1.24, installed: 1.23.5]
      - setuptools [required: Any, installed: 65.5.0]
    - stochastic [required: Any, installed: 0.7.0]
      - numpy [required: >=1.19,<2.0, installed: 1.23.5]
      - scipy [required: >=1.8,<2.0, installed: 1.9.3]
        - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
  - ipywidgets [required: Any, installed: 8.0.2]
    - ipykernel [required: >=4.5.1, installed: 6.16.1]
      - debugpy [required: >=1.0, installed: 1.6.3]
      - ipython [required: >=7.23.1, installed: 8.5.0]
        - backcall [required: Any, installed: 0.2.0]
        - colorama [required: Any, installed: 0.4.6]
        - decorator [required: Any, installed: 5.1.1]
        - jedi [required: >=0.16, installed: 0.18.1]
          - parso [required: >=0.8.0,<0.9.0, installed: 0.8.3]
        - matplotlib-inline [required: Any, installed: 0.1.6]
          - traitlets [required: Any, installed: 5.5.0]
        - pickleshare [required: Any, installed: 0.7.5]
        - prompt-toolkit [required: >3.0.1,<3.1.0, installed: 3.0.31]
          - wcwidth [required: Any, installed: 0.2.5]
        - pygments [required: >=2.4.0, installed: 2.13.0]
        - stack-data [required: Any, installed: 0.5.1]
          - asttokens [required: Any, installed: 2.0.8]
            - six [required: Any, installed: 1.16.0]
          - executing [required: Any, installed: 1.1.1]
          - pure-eval [required: Any, installed: 0.2.2]
        - traitlets [required: >=5, installed: 5.5.0]
      - jupyter-client [required: >=6.1.12, installed: 7.4.3]
        - entrypoints [required: Any, installed: 0.4]
        - jupyter-core [required: >=4.9.2, installed: 4.11.2]
          - pywin32 [required: >=1.0, installed: 304]
          - traitlets [required: Any, installed: 5.5.0]
        - nest-asyncio [required: >=1.5.4, installed: 1.5.6]
        - python-dateutil [required: >=2.8.2, installed: 2.8.2]
          - six [required: >=1.5, installed: 1.16.0]
        - pyzmq [required: >=23.0, installed: 24.0.1]
        - tornado [required: >=6.2, installed: 6.2]
        - traitlets [required: Any, installed: 5.5.0]
      - matplotlib-inline [required: >=0.1, installed: 0.1.6]
        - traitlets [required: Any, installed: 5.5.0]
      - nest-asyncio [required: Any, installed: 1.5.6]
      - packaging [required: Any, installed: 22.0]
      - psutil [required: Any, installed: 5.9.3]
      - pyzmq [required: >=17, installed: 24.0.1]
      - tornado [required: >=6.1, installed: 6.2]
      - traitlets [required: >=5.1.0, installed: 5.5.0]
    - ipython [required: >=6.1.0, installed: 8.5.0]
      - backcall [required: Any, installed: 0.2.0]
      - colorama [required: Any, installed: 0.4.6]
      - decorator [required: Any, installed: 5.1.1]
      - jedi [required: >=0.16, installed: 0.18.1]
        - parso [required: >=0.8.0,<0.9.0, installed: 0.8.3]
      - matplotlib-inline [required: Any, installed: 0.1.6]
        - traitlets [required: Any, installed: 5.5.0]
      - pickleshare [required: Any, installed: 0.7.5]
      - prompt-toolkit [required: >3.0.1,<3.1.0, installed: 3.0.31]
        - wcwidth [required: Any, installed: 0.2.5]
      - pygments [required: >=2.4.0, installed: 2.13.0]
      - stack-data [required: Any, installed: 0.5.1]
        - asttokens [required: Any, installed: 2.0.8]
          - six [required: Any, installed: 1.16.0]
        - executing [required: Any, installed: 1.1.1]
        - pure-eval [required: Any, installed: 0.2.2]
      - traitlets [required: >=5, installed: 5.5.0]
    - jupyterlab-widgets [required: ~=3.0, installed: 3.0.3]
    - traitlets [required: >=4.3.1, installed: 5.5.0]
    - widgetsnbextension [required: ~=4.0, installed: 4.0.3]
  - joblib [required: Any, installed: 1.2.0]
  - lightgbm [required: Any, installed: 3.3.3]
    - numpy [required: Any, installed: 1.23.5]
    - scikit-learn [required: !=0.22.0, installed: 1.2.0]
      - joblib [required: >=1.1.1, installed: 1.2.0]
      - numpy [required: >=1.17.3, installed: 1.23.5]
      - scipy [required: >=1.3.2, installed: 1.9.3]
        - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
      - threadpoolctl [required: >=2.0.0, installed: 3.1.0]
    - scipy [required: Any, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
    - wheel [required: Any, installed: 0.38.0]
      - setuptools [required: >=57.0.0, installed: 65.5.0]
  - lspopt [required: Any, installed: 1.2.0]
    - numpy [required: Any, installed: 1.23.5]
    - scipy [required: Any, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
    - six [required: Any, installed: 1.16.0]
  - matplotlib [required: Any, installed: 3.6.2]
    - contourpy [required: >=1.0.1, installed: 1.0.5]
      - numpy [required: >=1.16, installed: 1.23.5]
    - cycler [required: >=0.10, installed: 0.11.0]
    - fonttools [required: >=4.22.0, installed: 4.38.0]
    - kiwisolver [required: >=1.0.1, installed: 1.4.4]
    - numpy [required: >=1.19, installed: 1.23.5]
    - packaging [required: >=20.0, installed: 22.0]
    - pillow [required: >=6.2.0, installed: 9.2.0]
    - pyparsing [required: >=2.2.1, installed: 3.0.9]
    - python-dateutil [required: >=2.7, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
  - mne [required: >=0.23, installed: 1.2.1]
    - decorator [required: Any, installed: 5.1.1]
    - jinja2 [required: Any, installed: 3.1.2]
      - MarkupSafe [required: >=2.0, installed: 2.1.1]
    - matplotlib [required: Any, installed: 3.6.2]
      - contourpy [required: >=1.0.1, installed: 1.0.5]
        - numpy [required: >=1.16, installed: 1.23.5]
      - cycler [required: >=0.10, installed: 0.11.0]
      - fonttools [required: >=4.22.0, installed: 4.38.0]
      - kiwisolver [required: >=1.0.1, installed: 1.4.4]
      - numpy [required: >=1.19, installed: 1.23.5]
      - packaging [required: >=20.0, installed: 22.0]
      - pillow [required: >=6.2.0, installed: 9.2.0]
      - pyparsing [required: >=2.2.1, installed: 3.0.9]
      - python-dateutil [required: >=2.7, installed: 2.8.2]
        - six [required: >=1.5, installed: 1.16.0]
    - numpy [required: >=1.15.4, installed: 1.23.5]
    - packaging [required: Any, installed: 22.0]
    - pooch [required: >=1.5, installed: 1.6.0]
      - appdirs [required: >=1.3.0, installed: 1.4.4]
      - packaging [required: >=20.0, installed: 22.0]
      - requests [required: >=2.19.0, installed: 2.28.1]
        - certifi [required: >=2017.4.17, installed: 2022.9.24]
        - charset-normalizer [required: >=2,<3, installed: 2.1.1]
        - idna [required: >=2.5,<4, installed: 3.4]
        - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.12]
    - scipy [required: >=1.1.0, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
    - tqdm [required: Any, installed: 4.64.1]
      - colorama [required: Any, installed: 0.4.6]
  - numba [required: Any, installed: 0.56.3]
    - llvmlite [required: >=0.39.0dev0,<0.40, installed: 0.39.1]
    - numpy [required: >=1.18,<1.24, installed: 1.23.5]
    - setuptools [required: Any, installed: 65.5.0]
  - numpy [required: >=1.16.5, installed: 1.23.5]
  - outdated [required: Any, installed: 0.2.1]
    - littleutils [required: Any, installed: 0.2.2]
    - requests [required: Any, installed: 2.28.1]
      - certifi [required: >=2017.4.17, installed: 2022.9.24]
      - charset-normalizer [required: >=2,<3, installed: 2.1.1]
      - idna [required: >=2.5,<4, installed: 3.4]
      - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.12]
  - pandas [required: Any, installed: 1.5.1]
    - numpy [required: >=1.21.0, installed: 1.23.5]
    - python-dateutil [required: >=2.8.1, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
    - pytz [required: >=2020.1, installed: 2022.5]
  - pyriemann [required: >=0.2.7, installed: 0.3]
    - joblib [required: Any, installed: 1.2.0]
    - numpy [required: Any, installed: 1.23.5]
    - pandas [required: Any, installed: 1.5.1]
      - numpy [required: >=1.21.0, installed: 1.23.5]
      - python-dateutil [required: >=2.8.1, installed: 2.8.2]
        - six [required: >=1.5, installed: 1.16.0]
      - pytz [required: >=2020.1, installed: 2022.5]
    - scikit-learn [required: Any, installed: 1.2.0]
      - joblib [required: >=1.1.1, installed: 1.2.0]
      - numpy [required: >=1.17.3, installed: 1.23.5]
      - scipy [required: >=1.3.2, installed: 1.9.3]
        - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
      - threadpoolctl [required: >=2.0.0, installed: 3.1.0]
    - scipy [required: Any, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
  - scikit-learn [required: Any, installed: 1.2.0]
    - joblib [required: >=1.1.1, installed: 1.2.0]
    - numpy [required: >=1.17.3, installed: 1.23.5]
    - scipy [required: >=1.3.2, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
    - threadpoolctl [required: >=2.0.0, installed: 3.1.0]
  - scipy [required: Any, installed: 1.9.3]
    - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
  - seaborn [required: Any, installed: 0.12.1]
    - matplotlib [required: >=3.1,!=3.6.1, installed: 3.6.2]
      - contourpy [required: >=1.0.1, installed: 1.0.5]
        - numpy [required: >=1.16, installed: 1.23.5]
      - cycler [required: >=0.10, installed: 0.11.0]
      - fonttools [required: >=4.22.0, installed: 4.38.0]
      - kiwisolver [required: >=1.0.1, installed: 1.4.4]
      - numpy [required: >=1.19, installed: 1.23.5]
      - packaging [required: >=20.0, installed: 22.0]
      - pillow [required: >=6.2.0, installed: 9.2.0]
      - pyparsing [required: >=2.2.1, installed: 3.0.9]
      - python-dateutil [required: >=2.7, installed: 2.8.2]
        - six [required: >=1.5, installed: 1.16.0]
    - numpy [required: >=1.17, installed: 1.23.5]
    - pandas [required: >=0.25, installed: 1.5.1]
      - numpy [required: >=1.21.0, installed: 1.23.5]
      - python-dateutil [required: >=2.8.1, installed: 2.8.2]
        - six [required: >=1.5, installed: 1.16.0]
      - pytz [required: >=2020.1, installed: 2022.5]
  - sleepecg [required: >=0.5.0, installed: 0.5.2]
    - numpy [required: >=1.20.0, installed: 1.23.5]
    - PyYAML [required: >=5.4.0, installed: 6.0]
    - requests [required: >=2.25.0, installed: 2.28.1]
      - certifi [required: >=2017.4.17, installed: 2022.9.24]
      - charset-normalizer [required: >=2,<3, installed: 2.1.1]
      - idna [required: >=2.5,<4, installed: 3.4]
      - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.12]
    - scipy [required: >=1.7.0, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
    - tqdm [required: >=4.60.0, installed: 4.64.1]
      - colorama [required: Any, installed: 0.4.6]
  - tensorpac [required: >=0.6.5, installed: 0.6.5]
    - joblib [required: Any, installed: 1.2.0]
    - numpy [required: Any, installed: 1.23.5]
    - scipy [required: Any, installed: 1.9.3]
      - numpy [required: >=1.18.5,<1.26.0, installed: 1.23.5]
raphaelvallat commented 1 year ago

Thanks for the details. It seems like the matplotlib issue is caused by seaborn 0.12 having a strict requirement on matplotlib (matplotlib [required: >=3.1,!=3.6.1, installed: 3.6.2]). The numpy conflict is caused by numba having a strict numpy requirement numpy [required: >=1.18,<1.24, installed: 1.23.5].

I'm not sure how and why this impacted the plotting in YASA though. I'll leave this issue open in case other users encounter the same problem.

matiasandina commented 1 year ago

Also encountering this problem after numpy update

np.__version__
'1.24.2'

Issue happens directly on yasa import. I was able to downgrade numpy to 1.23.5 and it fixes the import issue.

umair-hassan commented 1 year ago

Creating a virtual environment (venv) helped resolve the issue for me. A virtual environment provides a self-contained Python environment with its own installed packages, separate from the system-wide Python installation. This allowed me to have different versions of packages and avoid conflicts between dependencies.

I also downloaded by enforcing to get out of python cache using this: pip install --no-cache-dir -r requirements.txt

the venv was just simply created in root directory using

python3 -m venv mycurrentdirectory

@raphaelvallat If you'd like, I can push a detailed introduction doc along with a helpful example to guide the user in setting up such venv YASA. Let me know, thanks!