Spaces:
Sleeping
Sleeping
Download tests/test_noise.py from yashmarathe/data-cleaning-openenv: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/yashmarathe/data-cleaning-openenv/resolve/main/tests/test_noise.py
- Command line
-
hf download hf://spaces/yashmarathe/data-cleaning-openenv/tests/test_noise.py
-
curl -L -o test_noise.py https://huggingface.co/spaces/yashmarathe/data-cleaning-openenv/resolve/main/tests/test_noise.py
1.69 kB
| """Tests for deterministic noise injection.""" | |
| from __future__ import annotations | |
| import pytest | |
| from data_cleaning_env.datasets import load_clean_dataset | |
| from data_cleaning_env.noise_injector import inject_noise | |
| class TestNoiseInjection: | |
| def test_deterministic_with_seed(self, task: str) -> None: | |
| clean_df, _ = load_clean_dataset(task) | |
| dirty1 = inject_noise(clean_df, task, seed=42) | |
| dirty2 = inject_noise(clean_df, task, seed=42) | |
| assert dirty1.shape[0] > 0 | |
| assert dirty1.equals(dirty2), f"{task}: noise injection is not deterministic" | |
| def test_noise_changes_data(self, task: str) -> None: | |
| clean_df, _ = load_clean_dataset(task) | |
| dirty = inject_noise(clean_df, task, seed=42) | |
| # The dirty df should differ from clean in at least some way | |
| assert not dirty.equals(clean_df) | |
| def test_severity_override(self) -> None: | |
| """Medium/hard/expert tasks use severity to scale noise intensity.""" | |
| clean_df, _ = load_clean_dataset("expert") | |
| low = inject_noise(clean_df, "expert", seed=42, severity=0.10) | |
| high = inject_noise(clean_df, "expert", seed=42, severity=0.90) | |
| # Higher severity should introduce more noise (missing values, etc.) | |
| assert low.isna().sum().sum() < high.isna().sum().sum() | |
| def test_unknown_task_raises(self) -> None: | |
| import pandas as pd | |
| df = pd.DataFrame({"a": [1, 2, 3]}) | |
| with pytest.raises(ValueError, match="Unknown task"): | |
| inject_noise(df, "nonexistent") | |