From 963d5845d765aadd80f0bed320d58ba0b6fe9927 Mon Sep 17 00:00:00 2001 From: Shing Chan Date: Sat, 28 Feb 2026 21:52:07 +0000 Subject: [PATCH 1/2] fix(test): correct test_read_csv_with_row_limits to match API semantics The test was misusing csv_start_row as a data row selector, but the API defines it as the file row where the header is located. Fixed by creating a CSV with preamble metadata lines so csv_start_row correctly points to the header row. Also removed unused imports and fixed spacing. --- tests/test_utils.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index a398502..ff1407f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,8 +13,6 @@ import numpy as np import pandas as pd from pathlib import Path -import tempfile -import shutil import json from stepcount import utils @@ -223,7 +221,7 @@ def test_impute_missing_preserves_valid_data(self, accel_data_1_5_days): def test_impute_missing_skip_full_missing_days(self): """Test that fully missing days are skipped.""" # Create data with one completely missing day - times = pd.date_range('2024-01-15', periods=2*24*3600*10, freq='100ms') + times = pd.date_range('2024-01-15', periods=2 * 24 * 3600 * 10, freq='100ms') data = pd.DataFrame( np.random.randn(len(times), 3) * 0.1 + [0, 0, 1], columns=['x', 'y', 'z'], @@ -396,8 +394,14 @@ def test_read_csv_basic(self, temp_csv_file, sample_rate): assert isinstance(data.index, pd.DatetimeIndex) def test_read_csv_with_row_limits(self, temp_dir, sample_rate): - """Test reading CSV with row limits.""" - # Create a small test CSV + """Test reading CSV with row limits (csv_start_row = header row, csv_end_row = last data row).""" + # Create a CSV with 3 metadata preamble lines, then header + 1000 data rows + # File layout: + # row 0: "# metadata line 1" + # row 1: "# metadata line 2" + # row 2: "# metadata line 3" + # row 3: "time,x,y,z" <-- header + # row 4..1003: data rows times = pd.date_range('2024-01-15', periods=1000, freq='100ms') df = pd.DataFrame({ 'time': times, @@ -406,13 +410,18 @@ def test_read_csv_with_row_limits(self, temp_dir, sample_rate): 'z': np.random.randn(1000) * 0.1 + 1.0 }) csv_path = temp_dir / "test_rows.csv" - df.to_csv(csv_path, index=False) - - # Read only rows 100-199 (100 rows) + with open(csv_path, 'w') as f: + f.write("# metadata line 1\n") + f.write("# metadata line 2\n") + f.write("# metadata line 3\n") + df.to_csv(csv_path, index=False, mode='a') + + # csv_start_row=3 means header is at file row 3 (skip preamble) + # csv_end_row=103 means stop at file row 103 (read 100 data rows: rows 4-103) data, info = utils.read( str(csv_path), - csv_start_row=100, - csv_end_row=199, + csv_start_row=3, + csv_end_row=103, sample_rate=sample_rate, resample_hz=None, verbose=False From a433e454fa45da0e50f8a1c8bc4e3a63e253f34c Mon Sep 17 00:00:00 2001 From: Shing Chan Date: Sat, 28 Feb 2026 21:55:25 +0000 Subject: [PATCH 2/2] ci: add pytest workflow with coverage --- .github/workflows/pytest.yaml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/pytest.yaml diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml new file mode 100644 index 0000000..b402051 --- /dev/null +++ b/.github/workflows/pytest.yaml @@ -0,0 +1,35 @@ +name: pytest + +on: + push: + branches: + - '**' + pull_request: + +jobs: + pytest: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v4 + + - name: Setup python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: setup.py + + - name: Install dependencies + run: | + set -e + pip install --upgrade pip + pip install -e .[dev] + + - name: Run tests with coverage + run: | + set -e + python -m pytest --cov --cov-report=term-missing --cov-report=xml