From 000ccf476231f2267d6aebe26f8402a88abe611c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 21:04:13 +0000 Subject: [PATCH] Remove unnecessary lambda expression --- monai/data/utils.py | 2 +- monai/handlers/utils.py | 10 +++++----- monai/transforms/intensity/array.py | 2 +- monai/transforms/utility/array.py | 10 +++++----- tests/test_intensity_stats.py | 2 +- tests/test_intensity_statsd.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/monai/data/utils.py b/monai/data/utils.py index a5cb5057d4..bd4dabed4c 100644 --- a/monai/data/utils.py +++ b/monai/data/utils.py @@ -1093,7 +1093,7 @@ def convert_tables_to_dicts( kwargs: additional arguments for `pandas.merge()` API to join tables. """ - df = reduce(lambda l, r: pd.merge(l, r, **kwargs), ensure_tuple(dfs)) + df = reduce(pd.merge, ensure_tuple(dfs)) # parse row indices rows: List[Union[int, str]] = [] if row_indices is None: diff --git a/monai/handlers/utils.py b/monai/handlers/utils.py index 15d2c59682..36b4819e55 100644 --- a/monai/handlers/utils.py +++ b/monai/handlers/utils.py @@ -130,12 +130,12 @@ class mean median max 5percentile 95percentile notnans if summary_ops is not None: supported_ops = OrderedDict( { - "mean": lambda x: np.nanmean(x), - "median": lambda x: np.nanmedian(x), - "max": lambda x: np.nanmax(x), - "min": lambda x: np.nanmin(x), + "mean": np.nanmean, + "median": np.nanmedian, + "max": np.nanmax, + "min": np.nanmin, "90percentile": lambda x: np.nanpercentile(x[0], x[1]), - "std": lambda x: np.nanstd(x), + "std": np.nanstd, "notnans": lambda x: (~np.isnan(x)).sum(), } ) diff --git a/monai/transforms/intensity/array.py b/monai/transforms/intensity/array.py index a8babfc659..3be205996e 100644 --- a/monai/transforms/intensity/array.py +++ b/monai/transforms/intensity/array.py @@ -1457,7 +1457,7 @@ def __call__(self, img: Union[np.ndarray, torch.Tensor]) -> Union[torch.Tensor, raise RuntimeError("Image needs a channel direction.") if isinstance(self.loc[0], int) and len(img.shape) == 4 and len(self.loc) == 2: raise RuntimeError("Input images of dimension 4 need location tuple to be length 3 or 4") - if isinstance(self.loc[0], Sequence) and len(img.shape) == 4 and min(map(lambda x: len(x), self.loc)) == 2: + if isinstance(self.loc[0], Sequence) and len(img.shape) == 4 and min(map(len, self.loc)) == 2: raise RuntimeError("Input images of dimension 4 need location tuple to be length 3 or 4") n_dims = len(img.shape[1:]) diff --git a/monai/transforms/utility/array.py b/monai/transforms/utility/array.py index 57d43db5d0..9d091f1b04 100644 --- a/monai/transforms/utility/array.py +++ b/monai/transforms/utility/array.py @@ -1091,11 +1091,11 @@ def __call__( img_ = img[mask] supported_ops = { - "mean": lambda x: np.nanmean(x), - "median": lambda x: np.nanmedian(x), - "max": lambda x: np.nanmax(x), - "min": lambda x: np.nanmin(x), - "std": lambda x: np.nanstd(x), + "mean": np.nanmean, + "median": np.nanmedian, + "max": np.nanmax, + "min": np.nanmin, + "std": np.nanstd, } def _compute(op: Callable, data: np.ndarray): diff --git a/tests/test_intensity_stats.py b/tests/test_intensity_stats.py index 059271e442..92a2c04585 100644 --- a/tests/test_intensity_stats.py +++ b/tests/test_intensity_stats.py @@ -31,7 +31,7 @@ ] TEST_CASE_3 = [ - {"ops": [lambda x: np.mean(x), "max", lambda x: np.min(x)], "key_prefix": "orig"}, + {"ops": [np.mean, "max", np.min], "key_prefix": "orig"}, np.array([[[0.0, 1.0], [2.0, 3.0]]]), None, {"orig_custom_0": 1.5, "orig_max": 3.0, "orig_custom_1": 0.0}, diff --git a/tests/test_intensity_statsd.py b/tests/test_intensity_statsd.py index 8c8bc8795a..596c80deb5 100644 --- a/tests/test_intensity_statsd.py +++ b/tests/test_intensity_statsd.py @@ -34,7 +34,7 @@ ] TEST_CASE_3 = [ - {"keys": "img", "ops": [lambda x: np.mean(x), "max", lambda x: np.min(x)], "key_prefix": "orig"}, + {"keys": "img", "ops": [np.mean, "max", np.min], "key_prefix": "orig"}, {"img": np.array([[[0.0, 1.0], [2.0, 3.0]]])}, "img_meta_dict", {"orig_custom_0": 1.5, "orig_max": 3.0, "orig_custom_1": 0.0},