I'm trying to reproduce this tutorial with my own data. I've a simple square grid of polygons:
from shapely import wkt
import pandas as pd
import geopandas as gpd
data_list = [
[0,51, wkt.loads("POLYGON ((-74816.7238 5017078.8988, -74716.7238 5017078.8988, -74716.7238 5016978.8988, -74816.7238 5016978.8988, -74816.7238 5017078.8988))")],
[1,91, wkt.loads("POLYGON ((-74816.7238 5016978.8988, -74716.7238 5016978.8988, -74716.7238 5016878.8988, -74816.7238 5016878.8988, -74816.7238 5016978.8988))")],
[2,88, wkt.loads("POLYGON ((-74816.7238 5016878.8988, -74716.7238 5016878.8988, -74716.7238 5016778.8988, -74816.7238 5016778.8988, -74816.7238 5016878.8988))")],
[3,54, wkt.loads("POLYGON ((-74816.7238 5016778.8988, -74716.7238 5016778.8988, -74716.7238 5016678.8988, -74816.7238 5016678.8988, -74816.7238 5016778.8988))")],
[4,51, wkt.loads("POLYGON ((-74816.7238 5016678.8988, -74716.7238 5016678.8988, -74716.7238 5016578.8988, -74816.7238 5016578.8988, -74816.7238 5016678.8988))")],
]
df = pd.DataFrame(data_list, columns=["id", "data", "geometry"])
gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=32633)
I've translate GeoPandas GeoDataFrame to SpatialPandas Geodataframe:
from spatialpandas import GeoDataFrame
sp_gdf = GeoDataFrame(gdf)
At this point I try to create a choropleth map according to this example:
import datashader as ds
canvas = ds.Canvas(plot_width=1000, plot_height=1000)
agg = canvas.polygons(sp_gdf, 'geometry', agg=ds.mean('data'))
But I'm facing in the error below:
AttributeError Traceback (most recent call last)
Cell In[7], line 4
1 import datashader as ds
3 canvas = ds.Canvas(plot_width=1000, plot_height=1000)
----> 4 agg = canvas.polygons(sp_gdf, 'geometry', agg=ds.mean('data'))
6 agg
File ~/.cache/pypoetry/virtualenvs/drakonotebook-larABRfp-py3.10/lib/python3.10/site-packages/datashader/core.py:753, in Canvas.polygons(self, source, geometry, agg)
751 agg = any_rdn()
752 glyph = PolygonGeom(geometry)
--> 753 return bypixel(source, self, glyph, agg)
File ~/.cache/pypoetry/virtualenvs/drakonotebook-larABRfp-py3.10/lib/python3.10/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 ~/.cache/pypoetry/virtualenvs/drakonotebook-larABRfp-py3.10/lib/python3.10/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'
I'm on Ubuntu 22.04, with Python 3.10 and the code above runs in a Jupyter Notebook. Below the version of libraries in use:
- shapely: 2.0.1
- pandas: 2.0.1
- geopandas: 0.12.2
- spatialpandas: 0.4.7
- datashader: 0.14.4
- numpy: 1.24.3
Moreover the python environment is managed by Poetry 1.4.2
NB: this thread is complete unuseful.
numpy.warnings
:>>> np.warnings
--><module 'warnings' from 'D:\\Anaconda3\\lib\\warnings.py'>
.>>> np.__version__
-->'1.21.5'
. But look, it looks likewarnings
is a module that is independent from Numpy and is just pointed to by numpy. Maybe try to look for and install a module calledwarnings
using PIP? – Worktablewarnings
is a package built-in in Python – Worktableimport numpy, warnings
and thennumpy.warnings = warnings
, as the first two lines of your script – Worktable