holoviz / datashader

Quickly and accurately render even the largest data.
http://datashader.org
BSD 3-Clause "New" or "Revised" License
3.26k stars 363 forks source link

`np.warnings` error with numpy 1.24 #1226

Closed stephenholtz closed 1 year ago

stephenholtz commented 1 year ago

OSX Ventura 13.2.1, using a minimal poetry environment in the terminal or vscode.

python = "3.11.*"
numpy = "^1.24.3"
datashader = "^0.14.4"
pandas = "^2.0.2"
ipykernel = "^6.23.1"

This code produces the np.warnings error.

import numpy as np
import pandas as pd
import datashader as ds

data = pd.DataFrame({'x': np.arange(0, 100), 'y': np.arange(0, 100)})
ds.Canvas().line(data, 'x', 'y')

ds.__version__
# '0.14.4'

np.__version__
# '1.24.3'

traceback:

AttributeError                            Traceback (most recent call last)
Cell In[7], line 4
      1 import pandas as pd
      3 data = pd.DataFrame({'x': np.arange(0, 100), 'y': np.arange(0, 100)})
----> 4 ds.Canvas().line(data, 'x', 'y')

File [~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/site-packages/datashader/core.py:450](https://file+.vscode-resource.vscode-cdn.net/Users/stephenholtz/repos/antenna-analysis/preprocessing/~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/site-packages/datashader/core.py:450), in Canvas.line(self, source, x, y, agg, axis, geometry, line_width, antialias)
    443     if not isinstance(non_cat_agg, (
    444         rd.any, rd.count, rd.max, rd.min, rd.sum, rd.summary, rd._sum_zero,
    445         rd.first, rd.last, rd.mean, rd.where
    446     )):
    447         raise NotImplementedError(
    448             f"{type(non_cat_agg)} reduction not implemented for antialiased lines")
--> 450 return bypixel(source, self, glyph, agg, antialias=glyph.antialiased)

File [~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/site-packages/datashader/core.py:1258](https://file+.vscode-resource.vscode-cdn.net/Users/stephenholtz/repos/antenna-analysis/preprocessing/~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/site-packages/datashader/core.py:1258), in bypixel(source, canvas, glyph, agg, antialias)
   1255 canvas.validate()
   1257 # All-NaN objects (e.g. chunks of arrays with no data) are valid in Datashader
-> 1258 with np.warnings.catch_warnings():
   1259     np.warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
   1260     return bypixel.pipeline(source, schema, canvas, glyph, agg, antialias=antialias)

File [~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/site-packages/numpy/__init__.py:320](https://file+.vscode-resource.vscode-cdn.net/Users/stephenholtz/repos/antenna-analysis/preprocessing/~/Library/Caches/pypoetry/virtualenvs/antenna-analysis-rqYsAEN9-py3.11/lib/python3.11/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 'warnings'

With numpy 1.23 this does not occur, it seems np.warnings was just warnings, however so hopefully this can be safely replaced with warnings.

It appears sklearn had a similar issue: https://github.com/scikit-learn/scikit-learn/pull/23654 (from here https://stackoverflow.com/questions/74863592/attributeerror-module-numpy-has-no-attribute-warnings)

I can try to fix this in a PR in the next day or so, unless someone else prefers to handle it.

hoxbro commented 1 year ago

Thank you for offering your help.

This is fixed in the latest datashader release 0.15, which was released this week.