mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.41k stars 1.91k forks source link

Error thrown upon import with `numpy` versions >= 1.24.0 #3413

Closed guhanrv closed 1 year ago

guhanrv commented 1 year ago

Hi all,

When I try to import the latest seaborn (0.12.2), I am getting an AttributeError on numpy:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 1
----> 1 import seaborn as sns

File /opt/conda/lib/python3.8/site-packages/seaborn/__init__.py:5
      3 from .utils import *  # noqa: F401,F403
      4 from .palettes import *  # noqa: F401,F403
----> 5 from .relational import *  # noqa: F401,F403
      6 from .regression import *  # noqa: F401,F403
      7 from .categorical import *  # noqa: F401,F403

File /opt/conda/lib/python3.8/site-packages/seaborn/relational.py:17
      8 from ._oldcore import (
      9     VectorPlotter,
     10 )
     11 from .utils import (
     12     locator_to_legend_entries,
     13     adjust_legend_subtitles,
     14     _default_color,
     15     _deprecate_ci,
     16 )
---> 17 from ._statistics import EstimateAggregator
     18 from .axisgrid import FacetGrid, _facet_docs
     19 from ._docstrings import DocstringComponents, _core_docs

File /opt/conda/lib/python3.8/site-packages/seaborn/_statistics.py:31
     29 import pandas as pd
     30 try:
---> 31     from scipy.stats import gaussian_kde
     32     _no_scipy = False
     33 except ImportError:

File /opt/conda/lib/python3.8/site-packages/scipy/stats/__init__.py:384
      1 """
      2 .. _statsrefmanual:
      3 
   (...)
    380 
    381 """
    382 from __future__ import division, print_function, absolute_import
--> 384 from .stats import *
    385 from .distributions import *
    386 from .morestats import *

File /opt/conda/lib/python3.8/site-packages/scipy/stats/stats.py:179
    176 from numpy import array, asarray, ma
    178 from scipy._lib.six import callable, string_types
--> 179 from scipy.spatial.distance import cdist
    180 from scipy.ndimage import measurements
    181 from scipy._lib._version import NumpyVersion

File /opt/conda/lib/python3.8/site-packages/scipy/spatial/__init__.py:97
      1 """
      2 =============================================================
      3 Spatial algorithms and data structures (:mod:`scipy.spatial`)
   (...)
     92 
     93 """
     95 from __future__ import division, print_function, absolute_import
---> 97 from .kdtree import *
     98 from .ckdtree import *
     99 from .qhull import *

File /opt/conda/lib/python3.8/site-packages/scipy/spatial/kdtree.py:8
      6 import numpy as np
      7 from heapq import heappush, heappop
----> 8 import scipy.sparse
     10 __all__ = ['minkowski_distance_p', 'minkowski_distance',
     11            'distance_matrix',
     12            'Rectangle', 'KDTree']
     15 def minkowski_distance_p(x, y, p=2):

File /opt/conda/lib/python3.8/site-packages/scipy/sparse/__init__.py:229
    223 # Original code by Travis Oliphant.
    224 # Modified and extended by Ed Schofield, Robert Cimrman,
    225 # Nathan Bell, and Jake Vanderplas.
    227 import warnings as _warnings
--> 229 from .base import *
    230 from .csr import *
    231 from .csc import *

File /opt/conda/lib/python3.8/site-packages/scipy/sparse/base.py:8
      6 from scipy._lib.six import xrange
      7 from scipy._lib._numpy_compat import broadcast_to
----> 8 from .sputils import (isdense, isscalarlike, isintlike,
      9                       get_sum_dtype, validateaxis, check_reshape_kwargs,
     10                       check_shape, asmatrix)
     12 __all__ = ['spmatrix', 'isspmatrix', 'issparse',
     13            'SparseWarning', 'SparseEfficiencyWarning']
     16 class SparseWarning(Warning):

File /opt/conda/lib/python3.8/site-packages/scipy/sparse/sputils.py:17
     11 __all__ = ['upcast', 'getdtype', 'isscalarlike', 'isintlike',
     12            'isshape', 'issequence', 'isdense', 'ismatrix', 'get_sum_dtype']
     14 supported_dtypes = ['bool', 'int8', 'uint8', 'short', 'ushort', 'intc',
     15                     'uintc', 'longlong', 'ulonglong', 'single', 'double',
     16                     'longdouble', 'csingle', 'cdouble', 'clongdouble']
---> 17 supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
     19 _upcast_memo = {}
     22 def upcast(*args):

File /opt/conda/lib/python3.8/site-packages/scipy/sparse/sputils.py:17, in <listcomp>(.0)
     11 __all__ = ['upcast', 'getdtype', 'isscalarlike', 'isintlike',
     12            'isshape', 'issequence', 'isdense', 'ismatrix', 'get_sum_dtype']
     14 supported_dtypes = ['bool', 'int8', 'uint8', 'short', 'ushort', 'intc',
     15                     'uintc', 'longlong', 'ulonglong', 'single', 'double',
     16                     'longdouble', 'csingle', 'cdouble', 'clongdouble']
---> 17 supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
     19 _upcast_memo = {}
     22 def upcast(*args):

File /opt/conda/lib/python3.8/site-packages/numpy/__init__.py:320, in __getattr__(attr)
    317     from .testing import Tester
    318     return Tester
--> 320 raise AttributeError("module {!r} has no attribute "
    321                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'typeDict'

I noticed that pyproject.toml within seaborn has the line "numpy>=1.20,!=1.24.0", and was wondering if this should be changed to "numpy>=1.20,<=1.24.0" instead?

I am reproducing my pip list below:

WARNING: Ignoring invalid distribution -eerml (/opt/conda/lib/python3.8/site-packages)
Package                            Version
---------------------------------- -------------------
absl-py                            0.12.0
aiohttp                            3.7.4.post0
alabaster                          0.7.12
alembic                            1.11.1
anndata                            0.9.1
anyio                              3.7.0
appdirs                            1.4.4
argon2-cffi                        20.1.0
arrow                              1.2.3
astroid                            2.5.6
astropy                            4.2.1
asttokens                          2.2.1
astunparse                         1.6.3
async-generator                    1.10
async-timeout                      3.0.1
atomicwrites                       1.4.0
attrs                              21.2.0
Automat                            20.2.0
autopep8                           1.5.5
Babel                              2.9.1
backcall                           0.2.0
backports.shutil-get-terminal-size 1.0.0
backports.zoneinfo                 0.2.1
batchglm                           0.7.4
bcrypt                             4.0.1
beautifulsoup4                     4.9.3
binaryornot                        0.4.4
biopython                          1.81
bitarray                           2.1.0
bkcharts                           0.2
black                              21.5b1
blaze                              0.10.1
bleach                             3.3.0
blessed                            1.20.0
bokeh                              2.3.2
boto                               2.49.0
boto3                              1.26.163
botocore                           1.29.163
Bottleneck                         1.3.2
boxsdk                             3.7.2
brewer2mpl                         1.4.1
Brotli                             1.0.9
brotlipy                           0.7.0
bs4                                0.0.1
bson                               0.5.10
cachetools                         4.2.2
cairocffi                          1.2.0
certifi                            2020.12.5
cffi                               1.14.5
cfgv                               3.3.1
chardet                            3.0.4
charset-normalizer                 3.1.0
click                              8.0.0
cloudpickle                        1.6.0
clyent                             1.2.1
cmake                              3.26.4
colorama                           0.4.4
conda                              4.10.1
conda-package-handling             1.7.3
configobj                          5.0.6
constantly                         15.1.0
contextlib2                        0.6.0.post1
contourpy                          1.1.0
cookiecutter                       1.7.0
coverage                           5.5
croniter                           1.3.15
cryptography                       3.4.7
cx-Oracle                          8.1.0
cycler                             0.10.0
Cython                             0.29.23
cytoolz                            0.11.0
dash                               2.10.2
dash-core-components               2.0.0
dash-html-components               2.0.0
dash-table                         5.0.0
dask                               2021.4.1
databricks-cli                     0.17.7
datashape                          0.5.2
dateutils                          0.6.12
decorator                          4.4.2
deepdiff                           6.3.0
defusedxml                         0.7.1
deprecation                        2.1.0
diff-match-patch                   20200713
diffxpy                            0.7.4
distlib                            0.3.6
distributed                        2021.4.1
Django                             2.2.5
django-research                    1.8.0
dnspython                          2.3.0
docker                             6.1.3
docutils                           0.16
entrypoints                        0.3
et-xmlfile                         1.1.0
exceptiongroup                     1.1.1
executing                          1.2.0
fastapi                            0.88.0
fastcache                          1.1.0
fastcluster                        1.2.6
filelock                           3.12.2
flake8                             3.8.4
Flask                              2.0.0
Flask-Compress                     1.9.0
Flask-Cors                         3.0.10
fonttools                          4.40.0
fsspec                             2023.6.0
future                             0.18.2
gast                               0.3.3
gevent                             21.1.2
ggplot                             0.11.5
gitdb                              4.0.7
GitPython                          3.1.14
glob2                              0.7
gmpy2                              2.0.8
google-auth                        1.30.0
google-auth-oauthlib               0.4.4
google-pasta                       0.2.0
gprofiler-official                 1.0.0
greenlet                           1.1.0
grpcio                             1.37.1
gunicorn                           20.1.0
h11                                0.14.0
h5py                               3.8.0
HeapDict                           1.0.1
html5lib                           1.1
hyperlink                          21.0.0
hyperopt                           0.2.7
hypothesis                         6.12.0
identify                           2.5.24
idna                               2.10
igraph                             0.10.4
imageio                            2.9.0
imagesize                          1.2.0
importlib-metadata                 4.0.1
importlib-resources                5.12.0
incremental                        21.3.0
inflection                         0.5.1
iniconfig                          1.1.1
inquirer                           3.1.3
intervaltree                       3.1.0
ipdb                               0.13.13
ipykernel                          5.5.4
ipyparallel                        8.6.1
ipython                            8.12.2
ipython-genutils                   0.2.0
ipywidgets                         7.6.3
isort                              5.8.0
itsdangerous                       2.1.2
JayDeBeApi                         1.2.3
jdcal                              1.4.1
jedi                               0.17.2
jeepney                            0.6.0
Jinja2                             3.0.0
jinja2-time                        0.2.0
jmespath                           1.0.1
joblib                             1.0.1
JPype1                             1.2.1
json5                              0.9.5
jsonify                            0.5
jsonschema                         3.2.0
jupyter                            1.0.0
jupyter-client                     6.1.12
jupyter-codeserver-proxy           1.0b1
jupyter-console                    6.4.0
jupyter-contrib-core               0.4.2
jupyter-contrib-nbextensions       0.7.0
jupyter-core                       4.7.1
jupyter-highlight-selected-word    0.2.0
jupyter-nbextensions-configurator  0.6.3
jupyter-server                     1.7.0
jupyter-server-mathjax             0.2.2
jupyter-server-proxy               3.0.2
jupyterlab                         2.3.2
jupyterlab-git                     0.24.0
jupyterlab-pygments                0.1.2
jupyterlab-server                  1.2.0
jupyterlab-widgets                 1.0.0
kaleido                            0.2.1
Keras                              2.4.3
Keras-Preprocessing                1.1.2
keyring                            23.0.1
kiwisolver                         1.3.1
lazy-object-proxy                  1.6.0
lightning                          2.0.3
lightning-cloud                    0.5.36
lightning-utilities                0.8.0
lit                                16.0.5.post0
llvmlite                           0.40.1
locket                             0.2.1
lxml                               4.6.3
Mako                               1.2.4
Markdown                           3.3.4
markdown-it-py                     3.0.0
MarkupSafe                         2.0.0
matplotlib                         3.7.1
matplotlib-inline                  0.1.2
matplotlib-venn                    0.11.9
mccabe                             0.6.1
mdurl                              0.1.2
mistune                            0.8.4
mlflow                             2.4.1
mpltools                           0.2.0
mpmath                             1.2.1
msgpack                            1.0.2
multidict                          5.1.0
multipledispatch                   0.6.0
mypy-extensions                    0.4.3
natsort                            8.3.1
nbclassic                          0.2.8
nbclient                           0.5.3
nbconvert                          6.0.7
nbdime                             2.1.1
nbformat                           5.1.3
nest-asyncio                       1.5.1
networkx                           2.5.1
nltk                               3.6.2
nodeenv                            1.8.0
nose                               1.3.7
notebook                           6.3.0
numba                              0.57.1
numexpr                            2.7.3
numpy                              1.24.4
numpydoc                           1.1.0
nvidia-cublas-cu11                 11.10.3.66
nvidia-cuda-cupti-cu11             11.7.101
nvidia-cuda-nvrtc-cu11             11.7.99
nvidia-cuda-runtime-cu11           11.7.99
nvidia-cudnn-cu11                  8.5.0.96
nvidia-cufft-cu11                  10.9.0.58
nvidia-curand-cu11                 10.2.10.91
nvidia-cusolver-cu11               11.4.0.1
nvidia-cusparse-cu11               11.7.4.91
nvidia-nccl-cu11                   2.14.3
nvidia-nvtx-cu11                   11.7.91
oauthlib                           3.1.0
odo                                0.5.0
olefile                            0.46
openpyxl                           3.0.7
opt-einsum                         3.3.0
ordered-set                        4.1.0
packaging                          23.1
pandas                             1.2.4
pandocfilters                      1.4.3
paramiko                           3.2.0
parso                              0.7.0
partd                              1.2.0
path                               15.1.2
path.py                            12.5.0
pathlib2                           2.3.5
pathspec                           0.8.1
patsy                              0.5.3
pep8                               1.7.1
pexpect                            4.8.0
pickleshare                        0.7.5
Pillow                             8.2.0
pip                                23.1.2
pkginfo                            1.7.0
platformdirs                       3.5.3
plotly                             5.15.0
pluggy                             0.13.1
ply                                3.11
polling2                           0.4.6
poyo                               0.5.0
pre-commit                         3.3.2
prometheus-client                  0.10.1
prompt-toolkit                     3.0.38
protobuf                           3.16.0
psutil                             5.8.0
psycopg2-binary                    2.8.6
ptyprocess                         0.7.0
pure-eval                          0.2.2
py                                 1.10.0
py4j                               0.10.9.7
pyarrow                            12.0.1
pyasn1                             0.4.8
pyasn1-modules                     0.2.8
pycodestyle                        2.6.0
pycosat                            0.6.3
pycparser                          2.20
pycrypto                           2.6.1
pycurl                             7.43.0.6
pydantic                           1.10.9
pydocstyle                         6.0.0
pyerfa                             1.7.3
pyflakes                           2.2.0
Pygments                           2.15.1
PyJWT                              2.7.0
pylint                             2.8.2
pyls-black                         0.4.6
pyls-spyder                        0.3.2
pymongo                            4.4.0
PyNaCl                             1.5.0
pynndescent                        0.5.10
pyodbc                             4.0.30
pyopenms                           2.7.0
pyOpenSSL                          20.0.1
pypandoc                           1.5
pyparsing                          2.4.7
PyQt5                              5.12.3
PyQt5-sip                          12.9.0
PyQtWebEngine                      5.12.1
pyquickbase                        0.0.6
pyro-api                           0.1.2
pyro-ppl                           1.8.5
pyrsistent                         0.17.3
pysam                              0.21.0
pysftp                             0.2.9
PySocks                            1.7.1
pyteomics                          4.6
pytest                             6.2.4
pytest-arraydiff                   0.3
pytest-astropy                     0.8.0
pytest-astropy-header              0.1.2
pytest-cov                         2.11.1
pytest-doctestplus                 0.9.0
pytest-filter-subpackage           0.1.1
pytest-openfiles                   0.5.0
pytest-remotedata                  0.3.2
python-dateutil                    2.8.1
python-domino                      1.0.4
python-editor                      1.0.4
python-jsonrpc-server              0.4.0
python-language-server             0.36.2
python-multipart                   0.0.6
pytorch-lightning                  2.0.3
pytz                               2021.1
pytz-deprecation-shim              0.1.0.post0
PyWavelets                         1.1.1
pyxdg                              0.27
PyYAML                             5.4.1
pyzmq                              22.0.3
QDarkStyle                         3.0.2
qmplot                             0.3.2
qstylizer                          0.2.0
QtAwesome                          1.0.2
qtconsole                          5.1.0
QtPy                               1.9.0
querystring-parser                 1.2.4
readchar                           4.0.5
regex                              2021.4.4
requests                           2.31.0
requests-oauthlib                  1.3.0
requests-toolbelt                  1.0.0
rich                               13.4.2
rope                               0.19.0
rpy2                               3.5.12
rsa                                4.7.2
ruamel-yaml-conda                  0.15.100
s3fs                               0.4.2
s3transfer                         0.6.1
scanpy                             1.9.3
scikit-image                       0.18.1
scikit-learn                       0.24.2
scipy                              1.4.1
seaborn                            0.12.2
SecretStorage                      3.3.1
seerbio-library                    2.1.1
seerml                             0.0.1a1
seerml-source                      0.3.0
Send2Trash                         1.5.0
service-identity                   21.1.0
session-info                       1.0.0
setuptools                         52.0.0.post20210125
simpervisor                        0.4
simplegeneric                      0.8.1
singledispatch                     3.6.1
six                                1.15.0
smart-open                         6.3.0
smmap                              4.0.0
sniffio                            1.2.0
snowballstemmer                    2.1.0
sortedcollections                  2.1.0
sortedcontainers                   2.3.0
soupsieve                          2.2.1
sparse                             0.14.0
Sphinx                             3.5.4
sphinxcontrib-applehelp            1.0.2
sphinxcontrib-devhelp              1.0.2
sphinxcontrib-htmlhelp             1.0.3
sphinxcontrib-jsmath               1.0.1
sphinxcontrib-qthelp               1.0.3
sphinxcontrib-serializinghtml      1.1.4
sphinxcontrib-websupport           1.2.4
spyder                             5.0.2
spyder-kernels                     2.0.2
SQLAlchemy                         1.4.15
sqlparse                           0.4.4
stack-data                         0.6.2
starlette                          0.22.0
starsessions                       1.3.0
statsmodels                        0.14.0
stdlib-list                        0.8.0
sympy                              1.8
tables                             3.6.1
tabulate                           0.9.0
tblib                              1.7.0
tenacity                           8.2.2
tensorboard                        2.5.0
tensorboard-data-server            0.6.1
tensorboard-plugin-wit             1.8.0
tensorflow-estimator               2.3.0
termcolor                          1.1.0
terminado                          0.9.5
testpath                           0.4.4
textdistance                       4.2.1
texttable                          1.6.7
threadpoolctl                      2.1.0
three-merge                        0.1.1
tifffile                           2021.4.8
tinycss2                           1.1.0
toml                               0.10.2
tomli                              2.0.1
tomli_w                            1.0.0
toolz                              0.11.1
torch                              2.0.1
torchmetrics                       0.11.4
torchvision                        0.15.2
tornado                            6.1
tqdm                               4.59.0
traitlets                          5.9.0
triton                             2.0.0
Twisted                            21.2.0
typing_extensions                  4.6.3
tzdata                             2023.3
tzlocal                            4.3
ujson                              4.0.2
umap-learn                         0.5.3
unicodecsv                         0.14.1
UpSetPlot                          0.8.0
urllib3                            1.26.16
uvicorn                            0.22.0
uWSGI                              2.0.19.1
venn                               0.1.3
virtualenv                         20.23.0
watchdog                           1.0.2
wcwidth                            0.2.5
webencodings                       0.5.1
websocket                          0.2.1
websocket-client                   0.59.0
websockets                         11.0.3
Werkzeug                           2.0.0
wheel                              0.36.2
whichcraft                         0.6.1
widgetsnbextension                 3.5.1
wrapt                              1.12.1
wurlitzer                          2.1.0
xgboost                            1.7.5
xlrd                               2.0.1
XlsxWriter                         1.4.2
xlwt                               1.3.0
yapf                               0.31.0
yarl                               1.6.3
zict                               2.0.0
zipp                               3.4.1
zope.event                         4.5.0
zope.interface                     5.4.0
zstandard                          0.21.0

Thanks a bunch.

mwaskom commented 1 year ago

Your trace back is ultimately coming out of scipy. Do you have evidence this is a seaborn problem per se, or that you just happened to run into it because seaborn imports scipy?

guhanrv commented 1 year ago

I was at scipy==1.4.1 and upgraded to scipy>=1.5.0 and the problem was resolved. I believe the reason that it seaborn allowed such a downgraded version of scipy was because it is in the optional stats dependencies in the pyproject.toml?

mwaskom commented 1 year ago

Possibly? Seaborn only declares what versions of libraries it is directly known to be compatible with; interactions with dependencies would need to be handled by your package manager.

mwaskom commented 1 year ago

Closing as upstream issue