Deltares / hatyan

Harmonic tidal analysis and prediction
https://deltares.github.io/hatyan/
GNU General Public License v3.0
13 stars 2 forks source link

pandas Y-DEC freqstring is not supported #290

Closed veenstrajelmer closed 4 months ago

veenstrajelmer commented 4 months ago

The code below fails in python 3.9/3.12 on github, probably with new pandas version. See if we can fix support or temporarily require lower pandas version.

import os
import hatyan
import numpy as np

dir_testdata = r"c:\DATA\hatyan\tests\data_unitsystemtests"

# TODO: when the prediction function does not treat Y and M differently, this testcase can be dropped
file_data_comp0 = os.path.join(dir_testdata,'VLISSGN_obs1.txt')
ts_measurements_group0 = hatyan.read_dia(filename=file_data_comp0)

comp_mean, comp_all = hatyan.analysis(ts=ts_measurements_group0, const_list='month', nodalfactors=True, fu_alltimes=False, xfac=True, 
                                      analysis_perperiod="Y", return_allperiods=True)

ts_pred_atonce = hatyan.prediction(comp=comp_mean, times=ts_measurements_group0.index)

ts_pred_allyears = hatyan.prediction(comp=comp_all, timestep="60min")

expected_atonce = np.array([-1.38346859, -0.84555223, -0.21307598,  0.76601685,  1.91438215,
        2.16373654,  1.56241672,  0.86686561, -0.0329582 , -1.02668776])
expected_allyears = np.array([-1.38346859, -0.84555223, -0.21307598,  0.76601685,  1.91438215,
        2.16373654,  1.56241672,  0.86686561, -0.0329582 , -1.02668776])

assert np.allclose(ts_pred_atonce["values"].values[:10], expected_atonce)
assert np.allclose(ts_pred_allyears["values"].values[:10], expected_allyears)
assert len(ts_pred_atonce) == len(ts_pred_allyears)

Exception:

________________________ test_prediction_perperiod_year ________________________
tests/test_analysis_prediction.py:493: in test_prediction_perperiod_year
    ts_pred_allyears = hatyan.prediction(comp=comp_all, timestep="60min")
hatyan/deprecated.py:34: in wrapper
    return f(*args, **kwargs)
hatyan/analysis_prediction.py:533: in prediction
    raise Exception(f'unknown freqstr: {period_dt.freqstr}')
E   Exception: unknown freqstr: Y-DEC
veenstrajelmer commented 4 months ago

This is fixed by adding Y-DEC in hatyan.prediction() (besides A-DEC)