Skip to content

Commit

Permalink
chore: refactor (#43)
Browse files Browse the repository at this point in the history
* started internal refactor

* refactor tests

* ignore[call-overload]

* skip interrogate in ci as does't pick up @overload
  • Loading branch information
FBruzzesi authored May 12, 2024
1 parent fdd8577 commit 41c9591
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 256 deletions.
63 changes: 27 additions & 36 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:

interrogate:
lint-interrogate:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
Expand All @@ -16,33 +16,24 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: pip install interrogate==1.5.0
- name: Interrogate
run: make interrogate

lint:
needs: [interrogate]
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: pip install ."[lint]"
- name: Run linter
run: make lint
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
# - name: Install & run interrogate
# run: |
# uv pip install interrogate==1.5.0 --system
# make interrogate
- name: Install & run linter
run: |
uv pip install ."[lint]" --system
make lint
test:
needs: [lint]
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest
#, macos-latest
#, windows-latest
]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -52,12 +43,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: pip install ."[pandas,polars,test]"
- name: Run tests
run: make test
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies and run tests
run: |
uv pip install -e ."[pandas,polars,test]" --system
make test
doc-build:
runs-on: ubuntu-latest
Expand All @@ -68,9 +59,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: pip install ."[docs]"
- name: Build documentation
run: mkdocs build -v -s
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies and check docs can build
run: |
uv pip install ."[docs]" --system
mkdocs build -v -s
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ clean-folders:

lint:
ruff version
ruff check timebasedcv tests --fix
ruff format timebasedcv tests
ruff check timebasedcv tests --fix
ruff clean

test:
Expand All @@ -37,7 +37,10 @@ interrogate:
interrogate-badge:
interrogate --generate-badge docs/img/interrogate-shield.svg

check: interrogate lint test clean-folders
types:
mypy timebasedcv

check: interrogate lint test types clean-folders

docs-serve:
mkdocs serve
Expand Down
33 changes: 22 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ authors = [{name = "Francesco Bruzzesi"}]
dependencies = [
"numpy",
"narwhals>=0.7.15",
"scikit-learn>=0.19",
"typing-extensions>=4.4.0; python_version < '3.11'",
]

Expand Down Expand Up @@ -60,7 +61,6 @@ test = [
"pytest==7.2.0",
"pytest-xdist==3.2.1",
"coverage==7.2.1",
"scikit-learn>=0.19",
]

all = ["timebasedcv[pandas,polars]"]
Expand All @@ -74,32 +74,43 @@ packages = ["timebasedcv"]

[tool.ruff]
line-length = 120
target-version = "py38"

[tool.ruff.lint]
extend-select = [
"E",
"F",
"I",
# "N", # pep8-naming
"W",
"PERF",
"RUF",
]
select = ["ALL"]
ignore = [
"E731", # do not assign a `lambda` expression, use a `def`
"D100", # Checks for undocumented public module definitions.
"D104", # Checks for undocumented public package definitions.
"D107", # Checks for public __init__ method definitions that are missing docstrings.
"E731", # Checks for lambda expressions which are assigned to a variable.
"N803", # Checks for argument names that do not follow the snake_case convention.
# "EM101", # Checks for the use of string literals in exception constructors.
# "ISC001", # Checks for implicitly concatenated strings on a single line.
"RET505", # Checks for else statements with a return statement in the preceding if block.
"RET506",
# "TRY003", # Checks for long exception messages that are not defined in the exception class itself.
"DTZ"
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ANN", "D", "S101", "PT006", "PT007", "PLR0913"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.pyupgrade]
keep-runtime-typing = true

[tool.interrogate]
ignore-nested-functions = true
ignore-module = true
ignore-init-method = true
ignore-private = true
ignore-magic = true
ignore-property-decorators = true
ignore-overloaded-functions = true
fail-under = 95
exclude = ["timebasedcv/utils/_types.py"]
verbose = 2 # 0 (minimal output), 1 (-v), 2 (-vv)

[tool.mypy]
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import pytest


@pytest.fixture
@pytest.fixture()
def sample_list() -> List[int]:
"""Returns a sample list."""
return [1, 2, 3, 4, 5]


@pytest.fixture
@pytest.fixture()
def sample_pairs() -> List[Tuple[int, int]]:
"""Returns a sample list of pairs."""
return [(1, 2), (2, 3), (3, 4), (4, 5)]
20 changes: 13 additions & 7 deletions tests/splitstate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,27 @@ def test_splitstate_valid(


@pytest.mark.parametrize(
"train_start, exception_context",
"train_start, context",
[
(date(2023, 1, 1), pytest.raises(TypeError)),
(pd.Timestamp(2023, 1, 1), pytest.raises(TypeError)),
("2023-01-01", pytest.raises(TypeError)),
(datetime(2023, 2, 1), pytest.raises(ValueError)),
(date(2023, 1, 1), pytest.raises(TypeError, match="All attributes must be of type")),
(pd.Timestamp(2023, 1, 1), pytest.raises(TypeError, match="All attributes must be of type")),
("2023-01-01", pytest.raises(TypeError, match="All attributes must be of type")),
(
datetime(2023, 2, 1),
pytest.raises(
ValueError,
match="`train_start`, `train_end`, `forecast_start`, `forecast_end` must be ordered",
),
),
],
)
def test_splitstate_invalid(
train_start,
exception_context,
context,
):
"""Test the SplitState class with mixed input values types or unordered datetypes."""

with exception_context:
with context:
SplitState(
train_start=train_start,
train_end=datetime(2023, 1, 31),
Expand Down
Loading

0 comments on commit 41c9591

Please sign in to comment.