Skip to content

Commit

Permalink
DEPR pandas freqstr
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
kavvkon committed Feb 3, 2024
1 parent 4ea8482 commit 2842592
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion enlopy/__init__.py
Expand Up @@ -4,4 +4,4 @@
from .utils import *
__author__ = 'Konstantinos Kavvadias'
__license__ = 'BSD-3-Clause'
__version__ = "0.1.dev12"
__version__ = "0.1"
3 changes: 1 addition & 2 deletions enlopy/analysis.py
@@ -1,4 +1,3 @@
from __future__ import division
import numpy as np
import pandas as pd

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions enlopy/generate.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
4 changes: 2 additions & 2 deletions enlopy/utils.py
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_analysis.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generate.py
Expand Up @@ -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

Expand Down

0 comments on commit 2842592

Please sign in to comment.