From 2842592071d24853d5eb1aaa67514e6a1094bc9e Mon Sep 17 00:00:00 2001 From: Konstantinos Kavvadias Date: Sun, 4 Feb 2024 01:38:46 +0200 Subject: [PATCH] DEPR pandas freqstr Bump version --- enlopy/__init__.py | 2 +- enlopy/analysis.py | 3 +-- enlopy/generate.py | 5 ++--- enlopy/plot.py | 1 - enlopy/utils.py | 4 ++-- tests/test_analysis.py | 2 +- tests/test_generate.py | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/enlopy/__init__.py b/enlopy/__init__.py index 43dfec1..d9e49cb 100644 --- a/enlopy/__init__.py +++ b/enlopy/__init__.py @@ -4,4 +4,4 @@ from .utils import * __author__ = 'Konstantinos Kavvadias' __license__ = 'BSD-3-Clause' -__version__ = "0.1.dev12" +__version__ = "0.1" diff --git a/enlopy/analysis.py b/enlopy/analysis.py index dc635ee..4f65e88 100644 --- a/enlopy/analysis.py +++ b/enlopy/analysis.py @@ -1,4 +1,3 @@ -from __future__ import division import numpy as np import pandas as pd @@ -120,7 +119,7 @@ def get_load_archetypes(Load, k=2, x='hour', y='dayofyear', plot_diagnostics=Fal return clusters_center_dewhitened -def get_load_stats(Load, per='a') -> pd.DataFrame: +def get_load_stats(Load, per='Y') -> pd.DataFrame: """Find load profile characteristics. Among other it estimates: peak, load factor, base load factor, operating hours, Arguments: diff --git a/enlopy/generate.py b/enlopy/generate.py index 33c429b..084756a 100644 --- a/enlopy/generate.py +++ b/enlopy/generate.py @@ -2,7 +2,6 @@ """ Methods that generate or adjusted energy related timeseries based on given assumptions/input """ -from __future__ import absolute_import, division, print_function import numpy as np import pandas as pd @@ -395,11 +394,11 @@ def gen_demand_response(Load, percent_peak_hrs_month=0.03, percent_shifted=0.05, def hours_per_month(demand): """Assign to each row hours per month""" dic_hours_per_month = demand.groupby(demand.index.month).count().to_dict() - return demand.resample('m').transform(lambda x: list(map(dic_hours_per_month.get, x.index.month))) + return demand.resample('M').transform(lambda x: list(map(dic_hours_per_month.get, x.index.month))) # Monthly demand rank # TODO: parametrize: we can check peaks on a weekly or daily basis - demand_m_rank = demand.resample('m').transform(lambda x: x.rank(method='min', ascending=False)) + demand_m_rank = demand.resample('M').transform(lambda x: x.rank(method='min', ascending=False)) # find which hours are going to be shifted bool_shift_from = demand_m_rank <= np.round(hours_per_month(demand) * percent_peak_hrs_month) diff --git a/enlopy/plot.py b/enlopy/plot.py index e649b48..239d1c1 100644 --- a/enlopy/plot.py +++ b/enlopy/plot.py @@ -1,4 +1,3 @@ -from __future__ import division import matplotlib.pyplot as plt import matplotlib.cm as cm import pandas as pd diff --git a/enlopy/utils.py b/enlopy/utils.py index c60744b..b93e67a 100644 --- a/enlopy/utils.py +++ b/enlopy/utils.py @@ -34,11 +34,11 @@ def make_timeseries(x=None, year=None, length=None, startdate=None, freq=None): if freq is None: # Shortcuts: Commonly used frequencies are automatically assigned if len(x) == 8760 or len(x) == 8784: - freq = 'H' + freq = 'h' elif len(x) == 35040: freq = '15min' elif len(x) == 12: - freq = 'm' + freq = 'M' else: raise ValueError('Input vector length must be 12, 8760 or 35040. Otherwise freq has to be defined') diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 565c8b2..e9de60a 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -25,7 +25,7 @@ def test_reshape_multiannual_dataframe(): assert np.isclose(b.sum().sum(), a.sum()) def test_reshape_monthly_multiannual(): - ind = pd.DatetimeIndex(pd.date_range(start='Jan-1990', end='Jan-2017', freq='m')) + ind = pd.DatetimeIndex(pd.date_range(start='Jan-1990', end='Jan-2017', freq='M')) a = pd.DataFrame(np.random.rand(324), index=ind) b = reshape_timeseries(a, x='month', y='year', aggfunc='sum') assert b.shape == (27, 12) # 27 years, 12 months diff --git a/tests/test_generate.py b/tests/test_generate.py index 857a5cc..60c48c3 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -95,7 +95,7 @@ def test_disag_hourly_to_minutes(self): y = make_timeseries(y, freq='h') disag_profile = np.random.rand(60) - y_disag = disag_upsample(y, disag_profile, to_offset='t') + y_disag = disag_upsample(y, disag_profile, to_offset='min') assert np.isclose(np.sum(y_disag), np.sum(y) ) # <= 0.001 #FIXME: np test equality assert len(y_disag) == 8760*60