Wrong sum stats
I recently computed the sum zonal stats for a shapefile with 416 admin 3 level boundaries and the values for some of the rows is way off. here is what it looks like:
FID | RASTERSTATS | QGIS
-----------------------------------
320 | 14925 | 12842
321 | 15032404941 | 13401
322 | 23455 | 19222
323 | 21474859155 | 23215
324 | 12884922386 | 23014
325 | 33255 | 22410
326 | 17179901970 | 33255
327 | 16922 | 32157
328 | 85899495020 | 16153
329 | 12884921516 | 13093
330 | 23524 | 21181
For values under FID, 321, 323, 334, 326, 328 and 329 the sum generated by rasterstats is way off. I saw similar issues but according to the thread, this is fixed by now. The data can be found here https://drive.google.com/file/d/1v-Y7cK7DOsrxIPG5h56H9Q_ij0YGVeCe/view?usp=sharing
I also included the script and if it can help here is a list of versions of packages on my pc:
numpy==1.14.3 GDAL==2.3.2 geopandas==0.4.0 rasterio==1.0.13 rasterstats==0.13.0
@adbeda thanks for the report. I'm not able to access those files on google drive, could you check the permissions?
sorry, check this one: https://drive.google.com/file/d/1v-Y7cK7DOsrxIPG5h56H9Q_ij0YGVeCe/view?usp=sharing
It looks like your script is incorrectly setting nodata.
GDAL confirms that the nodata value is 2147483647
gdalinfo /data/landscan/ls_2012_final_v2.tif | grep NoData
NoData Value=2147483647
When you set nodata=0 in your zonal_stats call, you're declaring that 0 is the true nodata value, which is incorrect. When it encounters one of these large values, it's considered valid since it's not equal to nodata.
Omitting the nodata argument will allow zonal_stats to read the true nodata value from the raster's metadata. That should fix the problem for polygons which intersect these nodata holes

Perfect. that makes a whole lot of sense now. Thanks!