diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92a7c17..22a6e60 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-ast - id: check-builtin-literals @@ -10,26 +10,33 @@ repos: - id: check-yaml - id: check-toml +- repo: https://github.com/nbQA-dev/nbQA + rev: 1.7.1 + hooks: + - id: nbqa-isort + - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - exclude: ^docs/ -- repo: https://github.com/psf/black - rev: 23.10.1 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.2.1 hooks: - - id: black - exclude: ^docs/ + - id: ruff-format + types_or: [python, pyi, jupyter] -- repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.1.3' +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: 'v0.2.0' hooks: - id: ruff + types_or: [python, pyi, jupyter] args: [ --fix, --exit-non-zero-on-fix ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.6.1 + rev: v1.8.0 hooks: - id: mypy - exclude: ^docs/ + language: system + pass_filenames: false + args: ['.'] diff --git a/CHANGELOG.md b/CHANGELOG.md index 669c3dd..f3fbaff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ## Version 0.4.3: September 12, 2022 -- Bugfix for computing the mean val score in CV +- Bugfix for computing the mean validation score in CV ## Version 0.4.2: September 12, 2022 diff --git a/pyproject.toml b/pyproject.toml index 70ce060..6e7c9c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [tool.black] -target-version = ['py39'] +target-version = ['py38'] line-length = 80 skip-string-normalization = false skip-magic-trailing-comma = false -extend-exclude = ''' +force-exclude = ''' /( | docs | setup.py @@ -11,39 +11,12 @@ extend-exclude = ''' ''' [tool.isort] -py_version = 39 -sections = [ - "FUTURE", - "STDLIB", - "THIRDPARTY", - "FIRSTPARTY", - "LOCALFOLDER" -] -default_section = "FIRSTPARTY" -known_third_party = [ - "numpy", - "pandas", - "keras", - "tensorflow", - "sklearn", - "matplotlib", - "scipy", - "h5py", - "seaborn", - "numba", - "gym", - "PyQt5", - "PyQt6", - "pyqtgraph", - "torch", - "tqdm", - "cv2", - "skimage", - "tensorflow_datasets", - "scikeras" -] +py_version = 38 +sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +default_section = "THIRDPARTY" +known_third_party = [] known_first_party = [] -known_local_folder = ["tensorcross"] +known_local_folder = [] # style: black multi_line_output = 3 include_trailing_comma = true @@ -54,14 +27,131 @@ line_length = 80 split_on_trailing_comma = true lines_after_imports = 2 force_single_line = true -skip_glob = [ - "docs/*", - "setup.py" +skip_glob = ["docs/*", "setup.py"] +filter_files = true + +[tool.ruff] +target-version = "py38" +line-length = 80 +indent-width = 4 +extend-exclude = ["docs", "test", "tests"] + +[tool.ruff.lint] +select = ["F", "E"] +extend-select = [ + "C90", + "I", + "N", + "UP", + "YTT", + "ANN", + "ASYNC", + "TRIO", + "S", + "BLE", + "B", + "A", + "COM", + "C4", + "DTZ", + "T10", + "DJ", + "EM", + "EXE", + "FA", + "ISC", + "ICN", + "G", + "INP", + "PIE", + "PYI", + "PT", + "Q", + "RSE", + "RET", + "SLOT", + "SIM", + "TID", + "TCH", + "INT", + "ARG", + "PTH", + "PD", + "PL", + "TRY", + "FLY", + "NPY", + "AIR", + "PERF", + "FURB", + "LOG", + "RUF", ] +ignore = [ + "ANN101", + "ANN102", + "I001", + "NPY002", + "INP001", + "TRY003", + "ISC001", + "COM812", + "UP", + "TCH003", + "ANN401", + "TCH", + "PTH", +] +fixable = ["ALL"] +unfixable = [] +preview = true +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.lint.isort] +force-single-line = true +force-sort-within-sections = false +lines-after-imports = 2 +known-first-party = [] +known-local-folder = [] +known-third-party = [] +section-order = [ + "future", + "standard-library", + "third-party", + "first-party", + "local-folder", +] + +[tool.ruff.lint.mccabe] +max-complexity = 24 + +[tool.ruff.lint.pycodestyle] +ignore-overlong-task-comments = true + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.flake8-annotations] +allow-star-arg-any = false +ignore-fully-untyped = false + +[tool.ruff.lint.pylint] +max-args = 5 +max-branches = 12 +max-locals = 15 +max-statements = 50 + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" +preview = false +docstring-code-format = true [tool.mypy] # Platform configuration -python_version = "3.8" +python_version = "3.10" # imports related ignore_missing_imports = true follow_imports = "silent" @@ -89,7 +179,7 @@ disallow_any_decorated = false disallow_any_explicit = false disallow_any_generics = false # Miscellaneous strictness flags -allow_untyped_globals = true +allow_untyped_globals = false allow_redefinition = false local_partial_types = false implicit_reexport = true @@ -98,56 +188,28 @@ strict_equality = true show_error_context = false show_column_numbers = false show_error_codes = true -exclude = ["examples"] - -[tool.ruff] -target-version = "py39" -select = ["F", "E"] -extend-select = ["W", "C90", "I", "N", "UP", "YTT", "ANN", "ASYNC", "B", "A", "C4", "DTZ", "FA", "ISC", "ICN", "PIE", "PYI", "PT", "RET", "SLOT", "SIM", "ARG", "PTH", "PD", "PLC", "PLE", "PLR", "PLW", "FLY", "NPY", "PERF", "RUF"] -ignore = ["I001", "ANN401", "SIM300", "PERF203", "ANN101", "B905", "UP007", "UP006", "PTH", "UP035"] -fixable = ["F", "E", "W", "C90", "I", "N", "UP", "YTT", "ANN", "ASYNC", "B", "A", "C4", "DTZ", "FA", "ISC", "ICN", "PIE", "PYI", "PT", "RET", "SLOT", "SIM", "ARG", "PTH", "PD", "PLC", "PLE", "PLR", "PLW", "FLY", "NPY", "PERF", "RUF"] -unfixable = [] -line-length = 80 -extend-exclude = ["tests", "test"] -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -[tool.ruff.isort] -force-single-line = true -force-sort-within-sections = false -lines-after-imports = 2 -[tool.ruff.mccabe] -max-complexity = 24 -[tool.ruff.pycodestyle] -ignore-overlong-task-comments = true -[tool.ruff.pydocstyle] -convention = "numpy" -[tool.ruff.flake8-annotations] -allow-star-arg-any = false -ignore-fully-untyped = false -[tool.ruff.format] -quote-style = "double" -indent-style = "space" -skip-magic-trailing-comma = false -line-ending = "auto" +exclude = ["docs", "test", "tests"] [tool.pyright] -pythonVersion = "3.9" +pythonVersion = "3.10" typeCheckingMode = "basic" # enable subset of "strict" reportDuplicateImport = true reportInvalidStubStatement = true reportOverlappingOverload = true reportPropertyTypeMismatch = true -reportUntypedClassDecorator = true +reportUntypedClassDecorator = false reportUntypedFunctionDecorator = true reportUntypedNamedTuple = true reportUnusedImport = true # disable subset of "basic" -reportGeneralTypeIssues = false +reportGeneralTypeIssues = true reportMissingModuleSource = false -reportOptionalCall = false -reportOptionalIterable = false -reportOptionalMemberAccess = false -reportOptionalOperand = false -reportOptionalSubscript = false -reportPrivateImportUsage = false +reportOptionalCall = true +reportOptionalIterable = true +reportOptionalMemberAccess = true +reportOptionalOperand = true +reportOptionalSubscript = true +reportPrivateImportUsage = true reportUnboundVariable = true +exclude = ["docs", "setup.py"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b3e1789..0000000 --- a/setup.cfg +++ /dev/null @@ -1,52 +0,0 @@ -[isort] -sections = - FUTURE, - STDLIB, - THIRDPARTY, - FIRSTPARTY, - LOCALFOLDER -default_section = FIRSTPARTY -known_third_party = - numpy, - pandas, - keras, - tensorflow, - sklearn, - matplotlib, - scipy, - h5py, - seaborn, - numba, - gym, - PyQt6, - PyQt5, - pyqtgraph -known_local_folder=tensorcross -multi_line_output = 3 -lines_after_imports = 2 -force_single_line = True -use_parentheses = True -ensure_newline_before_comments = True -line_length = 80 - - -[flake8] -exclude = .git,__pycache__,docs,old,build,dist -max-complexity = 30 -max-line-length = 80 -ignore=W504,F401,E402,E266,E203,W503,C408,C416,B001 - - -[mypy] -warn_return_any = true -warn_unused_configs = true -ignore_missing_imports = true -follow_imports = silent -check_untyped_defs = false -disallow_incomplete_defs = false -disallow_untyped_defs = false -disallow_subclassing_any = false -strict_optional = false -no_implicit_optional = false -warn_no_return = true -warn_unreachable = true diff --git a/tensorcross/model_selection/__init__.py b/tensorcross/model_selection/__init__.py index ea65ba4..ec48a47 100644 --- a/tensorcross/model_selection/__init__.py +++ b/tensorcross/model_selection/__init__.py @@ -8,9 +8,9 @@ __all__ = [ "BaseSearch", - "GridSearch", - "RandomSearch", "BaseSearchCV", + "GridSearch", "GridSearchCV", + "RandomSearch", "RandomSearchCV", ] diff --git a/tensorcross/model_selection/search.py b/tensorcross/model_selection/search.py index e5a2468..3477257 100644 --- a/tensorcross/model_selection/search.py +++ b/tensorcross/model_selection/search.py @@ -2,7 +2,7 @@ import logging import os -from abc import ABCMeta +from abc import ABC from abc import abstractmethod from collections.abc import Iterable from collections.abc import Mapping @@ -25,7 +25,7 @@ logger = tf.get_logger() -class BaseSearch(metaclass=ABCMeta): +class BaseSearch(ABC): """Abstract BaseSearch class for the grid or random search. Args: diff --git a/tensorcross/model_selection/search_cv.py b/tensorcross/model_selection/search_cv.py index a9912c2..c32f454 100644 --- a/tensorcross/model_selection/search_cv.py +++ b/tensorcross/model_selection/search_cv.py @@ -2,7 +2,7 @@ import logging import os -from abc import ABCMeta +from abc import ABC from abc import abstractmethod from collections.abc import Iterable from collections.abc import Mapping @@ -26,7 +26,7 @@ logger = tf.get_logger() -class BaseSearchCV(metaclass=ABCMeta): +class BaseSearchCV(ABC): """Abstract BaseSearchCV class for the grid or random search with cross validation. @@ -74,7 +74,8 @@ def _run_search( # noqa: PLR0912 Model or tf.keras.models.Sequential model. """ if len(dataset) == 0: - raise ValueError("Data Set is empty!") + error_msg = "Validation Set is empty!" + raise ValueError(error_msg) maximize = True tensorboard_callback: Optional[TensorBoard] = None @@ -112,7 +113,8 @@ def _run_search( # noqa: PLR0912 dataset=dataset, split_fraction=split_fraction, fold=fold ) if len(val_dataset) == 0: - raise ValueError("Val Set is empty!") + error_msg = "Validation Set is empty!" + raise ValueError(error_msg) if tensorboard_callback: if not os.path.exists(tensorboard_log_dir): diff --git a/tensorcross/utils/__init__.py b/tensorcross/utils/__init__.py index 0ef5532..8195581 100644 --- a/tensorcross/utils/__init__.py +++ b/tensorcross/utils/__init__.py @@ -2,4 +2,4 @@ from .dataset import dataset_split -__all__ = ["dataset_split", "dataset_join"] +__all__ = ["dataset_join", "dataset_split"]