Skip to content

Commit f393f27

Browse files
authored
[FIX] do not try to set n_cores on initialized objects (#930)
* do not try to set n_cores on initialized objects * hoist common code
1 parent db35391 commit f393f27

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

nimare/workflows/base.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ def _check_input(obj, clss, options, **kwargs):
6363
if obj == FWECorrector:
6464
kwargs["method"] = obj_str
6565

66-
return _check_type(obj, clss, **kwargs)
66+
# Apply kwargs (including n_cores) when obj is a class or string
67+
if isinstance(obj, (str, type)):
68+
return _check_type(obj, clss, **kwargs)
69+
70+
# If object is already instantiated, return it as-is
71+
return _check_type(obj, clss)
6772

6873

6974
class Workflow(NiMAREBase):
@@ -93,23 +98,25 @@ def _preprocess_input(self, estimator, corrector, diagnostics):
9398
diagnostics = [diagnostics]
9499

95100
# Check inputs and set defaults if input is None
96-
estimator = (
97-
self._estm_default(n_cores=self.n_cores)
98-
if estimator is None
99-
else _check_input(estimator, self._estm_base, self._estm_options, n_cores=self.n_cores)
100-
)
101-
102-
corrector = (
103-
self._corr_default(method=self._mcc_method, n_cores=self.n_cores)
104-
if corrector is None
105-
else _check_input(corrector, Corrector, self._corr_options, n_cores=self.n_cores)
106-
)
101+
if estimator is None:
102+
estimator = self._estm_default(n_cores=self.n_cores)
103+
else:
104+
estimator = _check_input(
105+
estimator, self._estm_base, self._estm_options, n_cores=self.n_cores
106+
)
107+
108+
if corrector is None:
109+
corrector = self._corr_default(method=self._mcc_method, n_cores=self.n_cores)
110+
else:
111+
corrector = _check_input(
112+
corrector, Corrector, self._corr_options, n_cores=self.n_cores
113+
)
107114

108115
diag_kwargs = {
109116
"voxel_thresh": self.voxel_thresh,
110117
"cluster_threshold": self.cluster_threshold,
111-
"n_cores": self.n_cores,
112118
}
119+
diag_kwargs["n_cores"] = self.n_cores
113120
if diagnostics is None:
114121
diagnostics = [self._diag_default(**diag_kwargs)]
115122
else:

0 commit comments

Comments
 (0)