diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ec3565..89553ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,10 @@ repos: rev: 1.13.0 hooks: - id: blacken-docs + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.0-alpha.4 hooks: diff --git a/pyproject.toml b/pyproject.toml index 1c39c05..1ee7f68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,9 @@ use_parentheses = true known_num = "networkx,numpy,pandas,scipy,sklearn,statmodels" known_plot = "matplotlib,mpl_toolkits,seaborn" known_bio = "anndata" -sections = "FUTURE,STDLIB,THIRDPARTY,NUM,PLOT,BIO,FIRSTPARTY,LOCALFOLDER" +known_r = "rpy2" +known_firstparty = "tradeseq" +sections = "FUTURE,STDLIB,THIRDPARTY,NUM,PLOT,R,BIO,FIRSTPARTY,LOCALFOLDER" no_lines_before = "LOCALFOLDER" balanced_wrapping = true length_sort = "0" @@ -43,7 +45,6 @@ select = [ "F", # Errors detected by Pyflakes "E", # Error detected by Pycodestyle "W", # Warning detected by Pycodestyle - "I", # isort "D", # pydocstyle "B", # flake8-bugbear "TID", # flake8-tidy-imports @@ -89,10 +90,9 @@ ignore = [ ] [tool.ruff.per-file-ignores] -"docs/*" = ["I", "BLE001"] +"docs/*" = ["BLE001"] "tests/*" = ["D"] "*/__init__.py" = ["F401"] -"scvelo/__init__.py" = ["I"] [tool.jupytext] formats = "ipynb,md" diff --git a/tests/core/test_base.py b/tests/core/test_base.py index 80b682b..ad163ee 100644 --- a/tests/core/test_base.py +++ b/tests/core/test_base.py @@ -1,11 +1,13 @@ from typing import Optional import hypothesis.strategies as st -import numpy as np -from anndata import AnnData from hypothesis.extra.numpy import arrays + +import numpy as np from scipy.sparse import csr_matrix +from anndata import AnnData + from tradeseq.gam import GAM MAX_INT_VALUE = 100 diff --git a/tests/core/tradeseq_r.py b/tests/core/tradeseq_r.py index 76e6550..d5b1dbe 100644 --- a/tests/core/tradeseq_r.py +++ b/tests/core/tradeseq_r.py @@ -1,4 +1,5 @@ import numpy as np + import rpy2.robjects as ro from rpy2.robjects import default_converter, numpy2ri from rpy2.robjects.conversion import localconverter diff --git a/tests/de_tests/test_association.py b/tests/de_tests/test_association.py index e8c2a65..b5d21a7 100644 --- a/tests/de_tests/test_association.py +++ b/tests/de_tests/test_association.py @@ -1,9 +1,10 @@ from typing import Literal -import numpy as np from hypothesis import given, settings from hypothesis import strategies as st +import numpy as np + from tests.core.test_base import get_gam from tradeseq.de_tests._association_test import AssociationTest from tradeseq.gam import GAM diff --git a/tests/de_tests/test_diff_end.py b/tests/de_tests/test_diff_end.py index a1815c1..af56090 100644 --- a/tests/de_tests/test_diff_end.py +++ b/tests/de_tests/test_diff_end.py @@ -1,7 +1,8 @@ -import numpy as np from hypothesis import given, settings from hypothesis import strategies as st +import numpy as np + from tests.core.test_base import get_gam from tradeseq.de_tests._diff_end_test import DiffEndTest from tradeseq.gam import GAM diff --git a/tests/de_tests/test_pattern.py b/tests/de_tests/test_pattern.py index ea7d0f5..59a7915 100644 --- a/tests/de_tests/test_pattern.py +++ b/tests/de_tests/test_pattern.py @@ -1,7 +1,8 @@ -import numpy as np from hypothesis import given, settings from hypothesis import strategies as st +import numpy as np + from tests.core.test_base import get_gam from tradeseq.de_tests._pattern_test import PatternTest from tradeseq.gam import GAM diff --git a/tests/de_tests/test_start_vs_end.py b/tests/de_tests/test_start_vs_end.py index 6659b87..c38162a 100644 --- a/tests/de_tests/test_start_vs_end.py +++ b/tests/de_tests/test_start_vs_end.py @@ -1,7 +1,8 @@ -import numpy as np from hypothesis import given, settings from hypothesis import strategies as st +import numpy as np + from tests.core.test_base import get_gam from tradeseq.de_tests._start_vs_end_test import StartVsEndTest from tradeseq.gam import GAM diff --git a/tests/gam/test_fit.py b/tests/gam/test_fit.py index d192794..70d07fc 100644 --- a/tests/gam/test_fit.py +++ b/tests/gam/test_fit.py @@ -1,11 +1,13 @@ -import anndata as ad -import numpy as np from hypothesis import given, settings from hypothesis import strategies as st +import numpy as np + +import anndata as ad + from tests.core.test_base import get_gam from tests.core.tradeseq_r import TradeseqR -from tradeseq.gam._gam import GAM, _calculate_offset +from tradeseq.gam._gam import _calculate_offset, GAM class TestGAMFitting: diff --git a/tests/gam/test_getters.py b/tests/gam/test_getters.py index 6eed257..9d4f00d 100644 --- a/tests/gam/test_getters.py +++ b/tests/gam/test_getters.py @@ -1,10 +1,11 @@ -import numpy as np import pytest from hypothesis import assume, given, settings from hypothesis import strategies as st from hypothesis.extra.numpy import arrays -from tests.core.test_base import MAX_INT_VALUE, get_gam +import numpy as np + +from tests.core.test_base import get_gam, MAX_INT_VALUE from tradeseq.gam._gam import GAM diff --git a/tradeseq/_backend/_base.py b/tradeseq/_backend/_base.py index bbbd50b..62952b5 100644 --- a/tradeseq/_backend/_base.py +++ b/tradeseq/_backend/_base.py @@ -1,6 +1,5 @@ from abc import ABC, abstractmethod from typing import ( - TYPE_CHECKING, Any, Callable, Dict, @@ -8,16 +7,19 @@ Optional, Tuple, Type, + TYPE_CHECKING, Union, ) +from packaging.version import LegacyVersion, parse, Version + import pandas as pd + import rpy2.robjects as ro -from packaging.version import LegacyVersion, Version, parse from rpy2.rinterface_lib.embedded import RRuntimeError from rpy2.robjects import pandas2ri from rpy2.robjects.conversion import localconverter -from rpy2.robjects.packages import InstalledSTPackage, PackageNotInstalledError, importr +from rpy2.robjects.packages import importr, InstalledSTPackage, PackageNotInstalledError __all__ = ("TradeSeqTest", "register") diff --git a/tradeseq/_backend/_test.py b/tradeseq/_backend/_test.py index cb7100c..77f69e6 100644 --- a/tradeseq/_backend/_test.py +++ b/tradeseq/_backend/_test.py @@ -1,11 +1,13 @@ from abc import ABC from typing import Any, Literal, Optional, Sequence +from packaging.version import parse + import pandas as pd + import rpy2.robjects as ro -from packaging.version import parse -from tradeseq._backend._base import TradeSeqTest, _load_library, register +from tradeseq._backend._base import _load_library, register, TradeSeqTest # TODO: Add docstrings diff --git a/tradeseq/_base.py b/tradeseq/_base.py index 9e92c4c..94aada5 100644 --- a/tradeseq/_base.py +++ b/tradeseq/_base.py @@ -3,19 +3,21 @@ from abc import ABC, abstractmethod from contextlib import redirect_stderr from io import StringIO -from typing import TYPE_CHECKING, Any, Literal, Optional, Sequence, Sized, Tuple, Union +from typing import Any, Literal, Optional, Sequence, Sized, Tuple, TYPE_CHECKING, Union import numpy as np import pandas as pd +from scipy.sparse import issparse + import rpy2.robjects as ro -from anndata import AnnData from rpy2.rinterface_lib.embedded import RRuntimeError from rpy2.robjects import numpy2ri, pandas2ri from rpy2.robjects.conversion import localconverter from rpy2.robjects.packages import importr -from scipy.sparse import issparse -from tradeseq._backend._base import TradeSeqTest, _load_library +from anndata import AnnData + +from tradeseq._backend._base import _load_library, TradeSeqTest _PARALLEL = importr("BiocParallel") diff --git a/tradeseq/gam/_backend.py b/tradeseq/gam/_backend.py index 8897292..e93b12f 100644 --- a/tradeseq/gam/_backend.py +++ b/tradeseq/gam/_backend.py @@ -2,6 +2,7 @@ import numpy as np import pandas as pd + import rpy2.robjects as ro from rpy2.robjects import default_converter, numpy2ri, pandas2ri from rpy2.robjects.conversion import localconverter diff --git a/tradeseq/gam/_gam.py b/tradeseq/gam/_gam.py index 40a12fa..28f124f 100644 --- a/tradeseq/gam/_gam.py +++ b/tradeseq/gam/_gam.py @@ -1,13 +1,16 @@ import warnings from typing import List, Optional, Tuple, Union -import matplotlib.pyplot as plt +from conorm import tmm_norm_factors + import numpy as np import pandas as pd +from scipy.sparse import issparse + +import matplotlib.pyplot as plt import seaborn as sns + from anndata import AnnData -from conorm import tmm_norm_factors -from scipy.sparse import issparse from tradeseq.gam import _backend