ContextLab / hypertools

A Python toolbox for gaining geometric insights into high-dimensional data
http://hypertools.readthedocs.io/en/latest/
MIT License
1.83k stars 160 forks source link

Plotting animations in Jupyter does not seem to be compatible with current Numpy (version 2 or greater) #265

Open fomightez opened 2 months ago

fomightez commented 2 months ago

This is a follow-up to Plotting animations do not seem to be compatible with Jupyter Notebook 7; however, I think because the new issue with animations is isolatable to the version of Numpy, it probably deserves its own issue post.

Essentially, if you do as it says in Plotting animations do not seem to be compatible with Jupyter Notebook 7 and specify Numpy to not be above version 1.26.4, the animation will work.

If you leave things unspecified so it gets current Numpy, which is v2.1.1, then you get the following when you run the code:

AttributeError: np.string_was removed in the NumPy 2.0 release. Use np.bytes_ instead.

You can easily test this going here and following the steps outlined there. If you skip the step specifying the numpy version, you'll see the error.

Full traceback seen when initiating animation when using Numpy 2.1.1 Even when ipympl is installed, working, and specified and you use the version of Hypertools obtained with `pip install git+https://github.com/ContextLab/hypertools.git`, you'll see the following whether using Python 3.11 or 3.10: ```python --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[1], line 6 4 import numpy as np 5 arr = np.array( [[math.sin(3*i[/100](https://hub.ovh2.mybinder.org/100)), math.cos (3*i[/100](https://hub.ovh2.mybinder.org/100)), (1[/100](https://hub.ovh2.mybinder.org/100))**2, (i[/100](https://hub.ovh2.mybinder.org/100))**3, 1[/](https://hub.ovh2.mybinder.org/)(1+i[/100](https://hub.ovh2.mybinder.org/100))] for i in range(0,300)]) ----> 6 hyp.plot(arr, animate=True) File [/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/plot/backend.py:1070](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/plot/backend.py#line=1069), in manage_backend..plot_wrapper(*args, **kwargs) 1067 if BACKEND_WARNING is not None: 1068 warnings.warn(BACKEND_WARNING) -> 1070 return plot_func(*args, **kwargs) 1072 finally: 1073 # restore rcParams prior to plot 1074 with warnings.catch_warnings(): 1075 # if the matplotlibrc was cached from <=v3.3.0, a TON of 1076 # (harmless as of v3.2.0) MatplotlibDeprecationWarnings 1077 # about `axes.Axes3D`-related rcParams fields are issued File [/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/plot/plot.py:313](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/plot/plot.py#line=312), in plot(x, fmt, marker, markers, linestyle, linestyles, color, colors, palette, group, hue, labels, legend, title, size, elev, azim, ndims, model, model_params, reduce, cluster, align, normalize, n_clusters, save_path, animate, duration, tail_duration, rotations, zoom, chemtrails, precog, bullettime, frame_rate, interactive, explore, mpl_backend, show, transform, vectorizer, semantic, corpus, ax, frame_kwargs) 311 if transform is None: 312 raw = format_data(x, **text_args) --> 313 xform = analyze( 314 raw, 315 ndims=ndims, 316 normalize=normalize, 317 reduce=reduce, 318 align=align, 319 internal=True, 320 ) 321 else: 322 xform = transform File [/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/tools/analyze.py:53](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/tools/analyze.py#line=52), in analyze(data, normalize, reduce, ndims, align, internal) 9 """ 10 Wrapper function for normalize -> reduce -> align transformations. 11 (...) 49 50 """ 52 # return processed data ---> 53 return aligner(reducer(normalizer(data, normalize=normalize, internal=internal), 54 reduce=reduce, ndims=ndims, internal=internal), align=align) File [/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/_shared/helpers.py:159](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/_shared/helpers.py#line=158), in memoize..memoizer(*args, **kwargs) 157 key = str(args) + str(kwargs) 158 if key not in cache: --> 159 cache[key] = obj(*args, **kwargs) 160 return cache[key] File [/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/tools/reduce.py:95](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/hypertools/tools/reduce.py#line=94), in reduce(x, reduce, ndims, normalize, align, model, model_params, internal, format_data) 92 if reduce is None: 93 return x ---> 95 elif isinstance(reduce, (str, np.string_)): 96 model_name = reduce 97 model_params = { 98 'n_components': ndims 99 } File [/srv/conda/envs/notebook/lib/python3.11/site-packages/numpy/__init__.py:397](https://hub.ovh2.mybinder.org/srv/conda/envs/notebook/lib/python3.11/site-packages/numpy/__init__.py#line=396), in __getattr__(attr) 394 raise AttributeError(__former_attrs__[attr]) 396 if attr in __expired_attributes__: --> 397 raise AttributeError( 398 f"`np.{attr}` was removed in the NumPy 2.0 release. " 399 f"{__expired_attributes__[attr]}" 400 ) 402 if attr == "chararray": 403 warnings.warn( 404 "`np.chararray` is deprecated and will be removed from " 405 "the main namespace in the future. Use an array with a string " 406 "or bytes dtype instead.", DeprecationWarning, stacklevel=2) AttributeError: `np.string_` was removed in the NumPy 2.0 release. Use `np.bytes_` instead. ```