Skip to content

Commit b9c7b11

Browse files
committed
fix missing import making distributed optional
1 parent dd88867 commit b9c7b11

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

pmda/leaflet.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,20 @@ def run(self,
268268
if scheduler is None and n_jobs == 1:
269269
scheduler = 'single-threaded'
270270

271-
# fall back to multiprocessing, we tried everything
272-
if scheduler is None:
273-
scheduler = 'multiprocessing'
271+
if n_blocks is None:
272+
if scheduler == 'multiprocessing':
273+
n_blocks = n_jobs
274+
else:
275+
try:
276+
from dask import distributed
277+
if isinstance(scheduler, distributed.Client):
278+
n_blocks = len(scheduler.ncores())
279+
except ImportError:
280+
n_blocks = 1
281+
warnings.warn(
282+
"Couldn't guess ideal number of blocks from scheduler. "
283+
"Setting n_blocks=1. "
284+
"Please provide `n_blocks` in call to method.")
274285

275286
scheduler_kwargs = {'scheduler': scheduler}
276287
if scheduler == 'multiprocessing':

pmda/parallel.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,17 @@ def run(self,
315315
if n_blocks is None:
316316
if scheduler == 'multiprocessing':
317317
n_blocks = n_jobs
318-
elif isinstance(scheduler, dask.distributed.Client):
319-
n_blocks = len(scheduler.ncores())
320318
else:
321-
n_blocks = 1
322-
warnings.warn(
323-
"Couldn't guess ideal number of blocks from scheduler. "
324-
"Setting n_blocks=1. "
325-
"Please provide `n_blocks` in call to method.")
319+
try:
320+
from dask import distributed
321+
if isinstance(scheduler, distributed.Client):
322+
n_blocks = len(scheduler.ncores())
323+
except ImportError:
324+
n_blocks = 1
325+
warnings.warn(
326+
"Couldn't guess ideal number of blocks from scheduler. "
327+
"Setting n_blocks=1. "
328+
"Please provide `n_blocks` in call to method.")
326329

327330
scheduler_kwargs = {'scheduler': scheduler}
328331
if scheduler == 'multiprocessing':

0 commit comments

Comments
 (0)