From 5df57aef625cb7bac93fa0bc9b794a076b80bf84 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:22:39 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.6.5 → v0.8.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.5...v0.8.0) - [github.com/pre-commit/mirrors-mypy: v1.11.2 → v1.13.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.11.2...v1.13.0) - [github.com/nbQA-dev/nbQA: 1.8.7 → 1.9.1](https://github.com/nbQA-dev/nbQA/compare/1.8.7...1.9.1) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 384ef2229..aa4ad710b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 # Use the ref you want to point at + rev: v5.0.0 # Use the ref you want to point at hooks: - id: trailing-whitespace - id: check-ast @@ -16,7 +16,7 @@ repos: - id: check-toml - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.6.5' + rev: 'v0.8.0' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -25,7 +25,7 @@ repos: types_or: [python, jupyter] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v1.13.0 hooks: - id: mypy entry: python3 -m mypy --config-file pyproject.toml @@ -41,7 +41,7 @@ repos: entry: python3 -m nbstripout - repo: https://github.com/nbQA-dev/nbQA - rev: 1.8.7 + rev: 1.9.1 hooks: - id: nbqa-black - id: nbqa-ruff From d990a87aa97e44a611eefd9f651471b9e1d48f96 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:23:06 +0000 Subject: [PATCH 2/2] [pre-commit.ci] Add auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cyclops/data/features/medical_image.py | 13 ++++++++----- cyclops/evaluate/utils.py | 8 +++++--- cyclops/models/wrappers/pt_model.py | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cyclops/data/features/medical_image.py b/cyclops/data/features/medical_image.py index 7b7d9cae9..3dcfd9583 100644 --- a/cyclops/data/features/medical_image.py +++ b/cyclops/data/features/medical_image.py @@ -209,11 +209,14 @@ def decode_example( use_auth_token = token_per_repo_id.get(repo_id) except ValueError: use_auth_token = None - with xopen( - path, - "rb", - use_auth_token=use_auth_token, - ) as file_obj, BytesIO(file_obj.read()) as buffer: + with ( + xopen( + path, + "rb", + use_auth_token=use_auth_token, + ) as file_obj, + BytesIO(file_obj.read()) as buffer, + ): image, metadata = self._read_file_from_bytes(buffer) metadata["filename_or_obj"] = path diff --git a/cyclops/evaluate/utils.py b/cyclops/evaluate/utils.py index 835de6263..1bbe99d1e 100644 --- a/cyclops/evaluate/utils.py +++ b/cyclops/evaluate/utils.py @@ -159,9 +159,11 @@ def get_columns_as_array( if isinstance(columns, str): columns = [columns] - with dataset.formatted_as("arrow", columns=columns, output_all_columns=True) if ( - isinstance(dataset, Dataset) and dataset.format != "arrow" - ) else nullcontext(): + with ( + dataset.formatted_as("arrow", columns=columns, output_all_columns=True) + if (isinstance(dataset, Dataset) and dataset.format != "arrow") + else nullcontext() + ): out_arr = squeeze_all( xp.stack( [xp.asarray(dataset[col].to_pylist()) for col in columns], axis=-1 diff --git a/cyclops/models/wrappers/pt_model.py b/cyclops/models/wrappers/pt_model.py index 50b3a4302..37499dec2 100644 --- a/cyclops/models/wrappers/pt_model.py +++ b/cyclops/models/wrappers/pt_model.py @@ -968,14 +968,17 @@ def fit( splits_mapping["validation"] = val_split format_kwargs = {} if transforms is None else {"transform": transforms} - with X[train_split].formatted_as( - "custom" if transforms is not None else "torch", - columns=feature_columns + target_columns, - **format_kwargs, - ), X[val_split].formatted_as( - "custom" if transforms is not None else "torch", - columns=feature_columns + target_columns, - **format_kwargs, + with ( + X[train_split].formatted_as( + "custom" if transforms is not None else "torch", + columns=feature_columns + target_columns, + **format_kwargs, + ), + X[val_split].formatted_as( + "custom" if transforms is not None else "torch", + columns=feature_columns + target_columns, + **format_kwargs, + ), ): self.partial_fit( X, @@ -1309,7 +1312,7 @@ def save_model(self, filepath: str, overwrite: bool = True, **kwargs): if include_lr_scheduler: state_dict["lr_scheduler"] = self.lr_scheduler_.state_dict() # type: ignore[attr-defined] - epoch = kwargs.get("epoch", None) + epoch = kwargs.get("epoch") if epoch is not None: filename, extension = os.path.basename(filepath).split(".") filepath = join(