|
6 | 6 | # from rdtools.test.conftest import cods_normalized_daily |
7 | 7 |
|
8 | 8 |
|
| 9 | +def test_cods_with_nan_prefix(cods_normalized_daily): |
| 10 | + '''Test CODSAnalysis with data starting with NaN values''' |
| 11 | + # Add NaN values at the beginning |
| 12 | + data_with_nan_prefix = cods_normalized_daily.copy() |
| 13 | + data_with_nan_prefix.iloc[:5] = np.nan |
| 14 | + |
| 15 | + # Should work - the NaN prefix should be trimmed |
| 16 | + cods = soiling.CODSAnalysis(data_with_nan_prefix) |
| 17 | + assert len(cods.pm) == len(cods_normalized_daily) - 5, \ |
| 18 | + "NaN prefix was not trimmed correctly" |
| 19 | + assert not np.isnan(cods.pm.iloc[0]), \ |
| 20 | + "First value should not be NaN after trimming" |
| 21 | + |
| 22 | + |
| 23 | +def test_cods_non_daily_frequency_raises(): |
| 24 | + '''Test CODSAnalysis raises ValueError for non-daily frequency data''' |
| 25 | + # Create hourly data (non-daily frequency) |
| 26 | + hourly_index = pd.date_range('2019/01/01', periods=100, freq='h', tz='UTC') |
| 27 | + hourly_data = pd.Series(data=np.random.rand(100), index=hourly_index) |
| 28 | + |
| 29 | + with pytest.raises(ValueError, match="Daily performance metric series must have daily frequency"): |
| 30 | + soiling.CODSAnalysis(hourly_data) |
| 31 | + |
| 32 | + |
| 33 | +def test_cods_invalid_order_raises(cods_normalized_daily): |
| 34 | + '''Test iterative_signal_decomposition raises ValueError when SR not in order''' |
| 35 | + cods = soiling.CODSAnalysis(cods_normalized_daily) |
| 36 | + |
| 37 | + # order without 'SR' should raise ValueError |
| 38 | + with pytest.raises(ValueError, match="'SR' must be in argument 'order'"): |
| 39 | + cods.iterative_signal_decomposition(order=('SC', 'Rd')) |
| 40 | + |
| 41 | + |
| 42 | +def test_kalman_filter_prescient_cleaning_events_mismatch(cods_normalized_daily): |
| 43 | + '''Test Kalman filter raises ValueError for mismatched prescient_cleaning_events length''' |
| 44 | + cods = soiling.CODSAnalysis(cods_normalized_daily) |
| 45 | + |
| 46 | + # Create prescient_cleaning_events with wrong length but sum > 4 to trigger the check |
| 47 | + wrong_length_events = pd.Series([True, True, True, True, True, False, False, False, False, False], |
| 48 | + index=pd.date_range('2019/01/01', periods=10, freq='D')) |
| 49 | + |
| 50 | + with pytest.raises(ValueError, match="The indices of prescient_cleaning_events must correspond"): |
| 51 | + cods._Kalman_filter_for_SR(cods_normalized_daily, |
| 52 | + prescient_cleaning_events=wrong_length_events) |
| 53 | + |
| 54 | + |
9 | 55 | def test_iterative_signal_decomposition(cods_normalized_daily): |
10 | 56 | ''' Test iterative_signal_decomposition with fixed test case ''' |
11 | 57 | np.random.seed(1977) |
|
0 commit comments