Skip to content

Commit

Permalink
More compatibility fixes with new pandas version
Browse files Browse the repository at this point in the history
  • Loading branch information
kavvkon committed Feb 5, 2024
1 parent 2842592 commit cf52ac8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions enlopy/analysis.py
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion enlopy/plot.py
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/test_analysis.py
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generate.py
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Expand Up @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit cf52ac8

Please sign in to comment.