Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Run Unit Tests

on:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened, ready_for_review]

push:
branches: [ main ]

# Cancel older runs for the same PR to save minutes
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions:
contents: read

jobs:
tests:
name: Unit tests
runs-on: ubuntu-latest
timeout-minutes: 20
if: ${{ github.event.pull_request.draft == false || github.event_name == 'push' }}

strategy:
fail-fast: false
matrix:
python-version: ['3.12']

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
pip install . --group test

- name: Register hf-hydrodata credentials as a public user
env:
TEST_EMAIL_PUBLIC: ${{ secrets.TEST_EMAIL_PUBLIC }}
TEST_PIN_PUBLIC: ${{ secrets.TEST_PIN_PUBLIC }}
run: |
python utilities/set_test_credentials.py

- name: Run unit tests
run: |
pytest --verbose
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cssi_evaluation"
version = "0.1.4"
version = "0.1.5"
description = "Model evaluation functions for the CSSI project"
readme = {file = "README.md", content-type = "text/markdown"}
license = {file = "LICENSE"}
Expand Down
5 changes: 4 additions & 1 deletion src/cssi_evaluation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def initialize_metrics_df(obs_metadata_df, metrics_list):
["site_id", "site_name", "latitude", "longitude", "domain_i", "domain_j"]
].copy()
for m in metrics_list:
metrics_df[f"{m}"] = np.nan
if m == "condon":
metrics_df[f"{m}"] = ""
else:
metrics_df[f"{m}"] = np.nan

return metrics_df
6 changes: 3 additions & 3 deletions tests/cssi_evaluation/test_model_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_get_observations():
obs_metadata_df, obs_data_df = model_evaluation.get_observations(
mask, ij_bounds, grid, start_date, end_date, variable, temporal_resolution
)
assert obs_metadata_df.shape == (14, 32)
assert obs_metadata_df.shape[0] == 14
assert obs_data_df.shape == (48, 15)
assert "01447500" in obs_data_df.columns

Expand All @@ -49,7 +49,7 @@ def test_get_observations_nan_filter_sites_removed():
mask, ij_bounds, grid, start_date, end_date, variable, temporal_resolution
)

assert obs_metadata_df.shape == (7, 32)
assert obs_metadata_df.shape[0] == 7
assert obs_data_df.shape == (5, 8)
assert "01209500" not in obs_data_df.columns

Expand Down Expand Up @@ -78,7 +78,7 @@ def test_get_observations_nan_filter_sites_included():
remove_sites_no_data=False,
)

assert obs_metadata_df.shape == (8, 32)
assert obs_metadata_df.shape[0] == 8
assert obs_data_df.shape == (5, 9)
assert "01209500" in obs_data_df.columns

Expand Down
22 changes: 22 additions & 0 deletions utilities/set_test_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Set user credentials for hf_hydrodata package."""

# pylint: disable=C0413

import sys
import os

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
import hf_hydrodata as hf


def main():
"""Use environment variable secrets to set hf_hydrodata credentials
for GitHub Actions testing."""
test_email = str(os.environ["TEST_EMAIL_PUBLIC"])
test_pin = str(os.environ["TEST_PIN_PUBLIC"])

hf.register_api_pin(test_email, test_pin)


if __name__ == "__main__":
main()