diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index ec52d60..5d406c1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/enlopy/analysis.py b/enlopy/analysis.py index 4f65e88..eca0796 100644 --- a/enlopy/analysis.py +++ b/enlopy/analysis.py @@ -26,9 +26,15 @@ def reshape_timeseries(Load, x='dayofyear', y=None, aggfunc='sum'): raise ValueError('Works only with 1D') if x is not None: - a[x] = getattr(a.index, x) + if x == 'week': # For a strange reason pandas moved week accesor to isocalendar + a[x] = a.index.isocalendar()['week'] + else: + a[x] = getattr(a.index, x) if y is not None: - a[y] = getattr(a.index, y) + if y == 'week': + a[y] = a.index.isocalendar()['week'] + else: + a[y] = getattr(a.index, y) a = a.reset_index(drop=True) return a.pivot_table(index=x, columns=y, diff --git a/enlopy/plot.py b/enlopy/plot.py index 239d1c1..80be6b0 100644 --- a/enlopy/plot.py +++ b/enlopy/plot.py @@ -89,7 +89,7 @@ def plot_percentiles(Load, x='hour', zz='week', perc_list=[[5, 95], [25, 75], 50 if ax is None: # Hack for nice jupyter notebook compatibility ax=plt.gca() a = reshape_timeseries(Load, x=x, y=zz, aggfunc='mean') - xx = a.columns.values + xx = a.columns.to_list() # TODO: s 2s 3s instead of percentiles diff --git a/tests/test_analysis.py b/tests/test_analysis.py index e9de60a..666c51b 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -10,6 +10,12 @@ def test_reshape_timeseries(): assert b.shape == (24,365) assert np.isclose(b.sum().sum(), a.sum()) +def test_reshape_timeseries_week(): + a = np.random.rand(8760) + b = reshape_timeseries(a, x='hour', y='week', aggfunc='mean') + assert b.shape == (52,24) + assert np.isclose(b.mean().mean(), a.mean(),0.001) + def test_reshape_multiannual(): a = np.random.rand(8760*2) a = make_timeseries(a, year=2019, freq='h') diff --git a/tests/test_generate.py b/tests/test_generate.py index 60c48c3..ead8458 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -82,7 +82,7 @@ def test_disag_daily_to_hourly(self): x = np.arange(0, 365) y = (np.cos(2 * np.pi / 364 * x) * 50 + 100) - y = make_timeseries(y, freq='d') + y = make_timeseries(y, freq='D') disag_profile = np.random.rand(24) y_disag = disag_upsample(y, disag_profile) diff --git a/tests/test_utils.py b/tests/test_utils.py index f9395b7..d605c0b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -20,7 +20,7 @@ def test_ndarray_15m(self): def test_ndarray_x(self): a = np.random.rand(8730) - b = make_timeseries(a, freq='H') + b = make_timeseries(a, freq='h') assert isinstance(b, pd.Series) assert sum(a) == sum(b) @@ -47,11 +47,11 @@ def test_2d_ndarray(self): def test_empty_frame(self): a = np.array([]) - b = make_timeseries(a, freq='H') + b = make_timeseries(a, freq='h') assert type(b) == pd.Series and len(b)==0 def test_empty_frame_to_indexed_empty(self): - b = make_timeseries(freq='H', length=8760) + b = make_timeseries(freq='h', length=8760) assert isinstance(b, pd.Series) and len(b) == 8760 def test_multiannual_timeseries(self):