From a0b4422839b523c252390021b0b25f1b13a5cecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 4 Sep 2025 20:49:27 +0200 Subject: [PATCH 1/3] fix: Don't crash computer --- datashader/resampling.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/datashader/resampling.py b/datashader/resampling.py index bdfa1efc1..d27219c09 100644 --- a/datashader/resampling.py +++ b/datashader/resampling.py @@ -179,13 +179,19 @@ def compute_chunksize(src, w, h, chunksize=None, max_mem=None): chunksize : tuple(int, int) Size of the output chunks. """ + sh, sw = src.shape + height_fraction, width_fraction = sh / h, sw / w + # For downsampling, use smaller chunks to reduce memory usage + if chunksize is None and (w < sw or h < sh): + src_chunks = src.chunksize + new_chunk_h = max(32, int(src_chunks[0] / height_fraction)) + new_chunk_w = max(32, int(src_chunks[1] / width_fraction)) + chunksize = (new_chunk_h, new_chunk_w) + start_chunksize = src.chunksize if chunksize is None else chunksize if max_mem is None: return start_chunksize - sh, sw = src.shape - height_fraction = float(sh)/h - width_fraction = float(sw)/w ch, cw = start_chunksize dim = True nbytes = src.dtype.itemsize From ed2f7a90d113a8ffec5cbab065781c7d33d8a3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 4 Sep 2025 21:18:27 +0200 Subject: [PATCH 2/3] Use truediv --- datashader/resampling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datashader/resampling.py b/datashader/resampling.py index d27219c09..27723dfcf 100644 --- a/datashader/resampling.py +++ b/datashader/resampling.py @@ -184,8 +184,8 @@ def compute_chunksize(src, w, h, chunksize=None, max_mem=None): # For downsampling, use smaller chunks to reduce memory usage if chunksize is None and (w < sw or h < sh): src_chunks = src.chunksize - new_chunk_h = max(32, int(src_chunks[0] / height_fraction)) - new_chunk_w = max(32, int(src_chunks[1] / width_fraction)) + new_chunk_h = max(32, src_chunks[0] // height_fraction) + new_chunk_w = max(32, src_chunks[1] // width_fraction) chunksize = (new_chunk_h, new_chunk_w) start_chunksize = src.chunksize if chunksize is None else chunksize From ff1e4c3199416d705c55c443b3a11131bbe8e884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 8 Sep 2025 08:37:40 +0200 Subject: [PATCH 3/3] convert back to int --- datashader/resampling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datashader/resampling.py b/datashader/resampling.py index 27723dfcf..d27219c09 100644 --- a/datashader/resampling.py +++ b/datashader/resampling.py @@ -184,8 +184,8 @@ def compute_chunksize(src, w, h, chunksize=None, max_mem=None): # For downsampling, use smaller chunks to reduce memory usage if chunksize is None and (w < sw or h < sh): src_chunks = src.chunksize - new_chunk_h = max(32, src_chunks[0] // height_fraction) - new_chunk_w = max(32, src_chunks[1] // width_fraction) + new_chunk_h = max(32, int(src_chunks[0] / height_fraction)) + new_chunk_w = max(32, int(src_chunks[1] / width_fraction)) chunksize = (new_chunk_h, new_chunk_w) start_chunksize = src.chunksize if chunksize is None else chunksize