Skip to content

Commit

Permalink
Merge pull request #1051 from oemof/fix/require_pandas_2
Browse files Browse the repository at this point in the history
Require pandas 2
  • Loading branch information
p-snft authored Jun 5, 2024
2 parents 2cba242 + 26c3e91 commit 5b52583
Show file tree
Hide file tree
Showing 43 changed files with 96 additions and 79 deletions.
12 changes: 6 additions & 6 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Both code blocks will create an hourly datetime index for 2011:
.. code-block:: python
import pandas as pd
my_index = pd.date_range('1/1/2011', periods=8761, freq='H')
my_index = pd.date_range('1/1/2011', periods=8761, freq='h')
This index can be used to define the EnergySystem:

Expand Down Expand Up @@ -816,7 +816,7 @@ This small example of PV, grid and SinkDSM shows how to use the component
data = pd.DataFrame.from_dict(data_dict)
# Do timestamp stuff
datetimeindex = pd.date_range(start='1/1/2013', periods=len(data.index), freq='H')
datetimeindex = pd.date_range(start='1/1/2013', periods=len(data.index), freq='h')
data['timestamp'] = datetimeindex
data.set_index('timestamp', inplace=True)
Expand Down Expand Up @@ -1030,10 +1030,10 @@ First, you start by defining your energy system as you might have done before, b
import pandas as pd
import oemof.solph as solph
my_index = pd.date_range('1/1/2013', periods=17520, freq='H')
my_index = pd.date_range('1/1/2013', periods=17520, freq='h')
periods = [
pd.date_range('1/1/2013', periods=8760, freq='H'),
pd.date_range('1/1/2014', periods=8760, freq='H'),
pd.date_range('1/1/2013', periods=8760, freq='h'),
pd.date_range('1/1/2014', periods=8760, freq='h'),
]
my_energysystem = solph.EnergySystem(timeindex=my_index, periods=periods)
Expand Down Expand Up @@ -1084,7 +1084,7 @@ So if you want to use this, the above would simplify to:
def determine_periods(datetimeindex):
...
my_index = pd.date_range('1/1/2013', periods=17520, freq='H')
my_index = pd.date_range('1/1/2013', periods=17520, freq='h')
periods = determine_periods(my_index) # Make use of method
my_energysystem = solph.EnergySystem(timeindex=my_index, periods=periods)
Expand Down
2 changes: 1 addition & 1 deletion examples/activity_costs/activity_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
# Calculate parameters and initialize the energy system and
##########################################################################
periods = 24
time = pd.date_range("1/1/2018", periods=periods, freq="H")
time = pd.date_range("1/1/2018", periods=periods, freq="h")

demand_heat = np.full(periods, 5)
demand_heat[:4] = 0
Expand Down
2 changes: 1 addition & 1 deletion examples/electrical/transshipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def draw_graph(


def main():
datetimeindex = pd.date_range("1/1/2017", periods=3, freq="H")
datetimeindex = pd.date_range("1/1/2017", periods=3, freq="h")

es = EnergySystem(timeindex=datetimeindex, infer_last_interval=False)

Expand Down
2 changes: 1 addition & 1 deletion examples/emission_constraint/emission_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
def main():
# create energy system
energysystem = solph.EnergySystem(
timeindex=pd.date_range("1/1/2012", periods=3, freq="H")
timeindex=pd.date_range("1/1/2012", periods=3, freq="h")
)

# create gas bus
Expand Down
2 changes: 1 addition & 1 deletion examples/flexible_modelling/add_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run_add_constraints_example(solver="cbc", nologg=False):
# ##### creating an oemof solph optimization model, nothing special here ##
# create an energy system object for the oemof solph nodes
es = EnergySystem(
timeindex=pd.date_range("1/1/2017", periods=5, freq="H"),
timeindex=pd.date_range("1/1/2017", periods=5, freq="h"),
infer_last_interval=False,
)
# add some nodes
Expand Down
2 changes: 1 addition & 1 deletion examples/flexible_modelling/saturating_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def saturating_storage_example():
# create an energy system
idx = pd.date_range("1/1/2023", periods=100, freq="H")
idx = pd.date_range("1/1/2023", periods=100, freq="h")
es = solph.EnergySystem(timeindex=idx, infer_last_interval=False)

# power bus
Expand Down
2 changes: 1 addition & 1 deletion examples/flow_count_limit/flow_count_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

def main():
energy_system = solph.EnergySystem(
timeindex=pd.date_range("1/1/2012", periods=4, freq="H")
timeindex=pd.date_range("1/1/2012", periods=4, freq="h")
)

bel = solph.Bus(label="bel")
Expand Down
2 changes: 1 addition & 1 deletion examples/gradient_example/gradient_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main():
# used.
gradient = 0.01

date_time_index = pd.date_range("1/1/2012", periods=48, freq="H")
date_time_index = pd.date_range("1/1/2012", periods=48, freq="h")
print(date_time_index)
energysystem = EnergySystem(
timeindex=date_time_index, infer_last_interval=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main():

# Change the index of data to be able to select data based on the time
# range.
data.index = pd.date_range(start="2022-01-01", periods=len(data), freq="H")
data.index = pd.date_range(start="2022-01-01", periods=len(data), freq="h")

# Choose the range of the solar potential and demand
# based on the selected simulation period.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def offset_converter_example():
data = pd.read_csv(filepath_or_buffer=filename)

# Change the index of data to be able to select data based on the time range.
data.index = pd.date_range(start="2022-01-01", periods=len(data), freq="H")
data.index = pd.date_range(start="2022-01-01", periods=len(data), freq="h")

# Choose the range of the solar potential and demand
# based on the selected simulation period.
Expand All @@ -100,7 +100,7 @@ def offset_converter_example():

# Create the energy system.
date_time_index = pd.date_range(
start=start_date, periods=n_days * 24, freq="H"
start=start_date, periods=n_days * 24, freq="h"
)
energy_system = solph.EnergySystem(timeindex=date_time_index)

Expand Down
2 changes: 1 addition & 1 deletion examples/storage_balanced_unbalanced/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def storage_example():
)

# create an energy system
idx = pd.date_range("1/1/2017", periods=len(timeseries), freq="H")
idx = pd.date_range("1/1/2017", periods=len(timeseries), freq="h")
es = solph.EnergySystem(timeindex=idx)

for data_set in DATA:
Expand Down
2 changes: 1 addition & 1 deletion examples/storage_costs/storage_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

def storage_costs_example():
# create an energy system
idx = pd.date_range("1/1/2023", periods=13, freq="H")
idx = pd.date_range("1/1/2023", periods=13, freq="h")
es = solph.EnergySystem(timeindex=idx, infer_last_interval=False)

# power bus
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies = [
"blinker",
"dill",
"numpy",
"pandas >= 1.5.3",
"pandas >= 2.0.0",
"pyomo >= 6.6.0, < 7.0",
"networkx",
"oemof.tools >= 0.4.3",
Expand Down
11 changes: 10 additions & 1 deletion src/oemof/solph/_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,13 @@ def create_time_index(
number = round(hoy / interval)
if start is None:
start = f"1/1/{year}"
return pd.date_range(start, periods=number + 1, freq=f"{interval}h")
try:
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}h"
)
except ValueError:
# Pandas <2.2 compatibility
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}H"
)
return time_index
4 changes: 1 addition & 3 deletions src/oemof/solph/components/_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def __init__(self, label=None, inputs=None, custom_attributes=None):
)

super().__init__(
label=label,
inputs=inputs,
custom_properties=custom_attributes
label=label, inputs=inputs, custom_properties=custom_attributes
)

def constraint_group(self):
Expand Down
4 changes: 1 addition & 3 deletions src/oemof/solph/components/_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def __init__(self, label=None, outputs=None, custom_attributes=None):
)

super().__init__(
label=label,
outputs=outputs,
custom_properties=custom_attributes
label=label, outputs=outputs, custom_properties=custom_attributes
)

def constraint_group(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/constraint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup_class(cls):
r"^objective.*(?=s\.t\.)", re.DOTALL | re.MULTILINE
)

cls.date_time_index = pd.date_range("1/1/2012", periods=3, freq="H")
cls.date_time_index = pd.date_range("1/1/2012", periods=3, freq="h")

cls.tmppath = solph.helpers.extend_basic_path("tmp")
logging.info(cls.tmppath)
Expand Down Expand Up @@ -1903,7 +1903,7 @@ def test_nonequidistant_storage(self):
"""Constraint test of an energy system
with non-equidistant time index
"""
idxh = pd.date_range("1/1/2017", periods=3, freq="H")
idxh = pd.date_range("1/1/2017", periods=3, freq="h")
idx2h = pd.date_range("1/1/2017 03:00:00", periods=2, freq="2H")
idx30m = pd.date_range("1/1/2017 07:00:00", periods=4, freq="30min")
timeindex = idxh.append([idx2h, idx30m])
Expand Down
8 changes: 4 additions & 4 deletions tests/multi_period_constraint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def setup_class(cls):
r"^objective.*(?=s\.t\.)", re.DOTALL | re.MULTILINE
)

timeindex1 = pd.date_range("1/1/2012", periods=2, freq="H")
timeindex2 = pd.date_range("1/1/2013", periods=2, freq="H")
timeindex3 = pd.date_range("1/1/2014", periods=2, freq="H")
timeindex1 = pd.date_range("1/1/2012", periods=2, freq="h")
timeindex2 = pd.date_range("1/1/2013", periods=2, freq="h")
timeindex3 = pd.date_range("1/1/2014", periods=2, freq="h")
cls.date_time_index = timeindex1.append(timeindex2).append(timeindex3)
cls.periods = [timeindex1, timeindex2, timeindex3]

Expand Down Expand Up @@ -2316,7 +2316,7 @@ def test_multi_period_varying_period_length(self):

# Create a list of timeindex for each period
periods = [
pd.date_range(f"1/1/{i}", periods=3, freq="H") for i in years
pd.date_range(f"1/1/{i}", periods=3, freq="h") for i in years
]

# Create an overall timeindex
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_version_metadata():


def test_wrong_logging_level():
datetimeindex = pd.date_range("1/1/2012", periods=12, freq="H")
datetimeindex = pd.date_range("1/1/2012", periods=12, freq="h")
es = solph.EnergySystem(timeindex=datetimeindex, infer_last_interval=True)
tools.logger.define_logging()
my_logger = logging.getLogger()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_constraints_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def test_special():
date_time_index = pd.date_range("1/1/2012", periods=5, freq="H")
date_time_index = pd.date_range("1/1/2012", periods=5, freq="h")
energysystem = solph.EnergySystem(
timeindex=date_time_index,
infer_last_interval=True,
Expand All @@ -28,7 +28,7 @@ def test_special():


def test_something_else():
date_time_index = pd.date_range("1/1/2012", periods=5, freq="H")
date_time_index = pd.date_range("1/1/2012", periods=5, freq="h")
energysystem = solph.EnergySystem(
timeindex=date_time_index, infer_last_interval=True
)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
)
def test_add_periods():
"""test method _add_periods of energy system"""
timeindex = pd.date_range(start="2012-01-01", periods=10000, freq="H")
timeindex = pd.date_range(start="2012-01-01", periods=10000, freq="h")
periods = [
pd.date_range(start="2012-01-01", periods=8784, freq="H"),
pd.date_range(start="2013-01-01", periods=1217, freq="H"),
pd.date_range(start="2012-01-01", periods=8784, freq="h"),
pd.date_range(start="2013-01-01", periods=1217, freq="h"),
]
es = EnergySystem(
timeindex=timeindex, periods=periods, infer_last_interval=True
)
assert len(es.periods) == 2
assert es.periods[0].equals(
pd.date_range(start="2012-01-01", periods=8784, freq="H")
pd.date_range(start="2012-01-01", periods=8784, freq="h")
)
assert es.periods[1].equals(
pd.date_range(start="2013-01-01", periods=1217, freq="H")
pd.date_range(start="2013-01-01", periods=1217, freq="h")
)


Expand All @@ -48,9 +48,9 @@ def test_add_periods():
)
def test_extract_periods_years():
"""test method _extract_periods_years of energy system"""
t_idx_1 = pd.date_range("1/1/2020", periods=3, freq="H").to_series()
t_idx_2 = pd.date_range("1/1/2041", periods=3, freq="H").to_series()
t_idx_3 = pd.date_range("1/1/2050", periods=3, freq="H").to_series()
t_idx_1 = pd.date_range("1/1/2020", periods=3, freq="h").to_series()
t_idx_2 = pd.date_range("1/1/2041", periods=3, freq="h").to_series()
t_idx_3 = pd.date_range("1/1/2050", periods=3, freq="h").to_series()
timeindex = pd.concat([t_idx_1, t_idx_2, t_idx_3]).index
periods = [t_idx_1, t_idx_2, t_idx_3]
es = EnergySystem(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_multi_period_default_discount_rate():

def test_cellular_structure_detection():
"""Test flag creation if list is passed as energysystem to model"""
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="H")
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="h")
es = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
ec_1 = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
ec_2 = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
Expand All @@ -125,7 +125,7 @@ def test_sub_cell_node_consideration():
Test if the nodes of sub-cells are considered for cellular
energysystems.
"""
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="H")
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="h")
es = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
ec_1 = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
bus_es = solph.buses.Bus(label="bus_es")
Expand All @@ -141,7 +141,7 @@ def test_sub_cell_flow_consideration():
Test if the flows of sub-cells are considered for cellular
energysystems.
"""
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="H")
timeindex = pd.date_range(start="2020-01-01", periods=1, freq="h")
es = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
ec_1 = solph.EnergySystem(timeindex=timeindex, infer_last_interval=True)
bus_es = solph.buses.Bus(label="bus_es")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_non_equidistant_time_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class TestParameterResult:
@classmethod
def setup_class(cls):
dtindex1 = pd.date_range("1/1/2012", periods=24, freq="H")
dtindex1 = pd.date_range("1/1/2012", periods=24, freq="h")
dtindex2 = pd.date_range("1/2/2012", periods=49, freq="30min")
dtindex = dtindex1.union(dtindex2)
es = EnergySystem(timeindex=dtindex, infer_last_interval=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_outputlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
conversion_factors={bel: 1 / 3, b_heat_source: (cop - 1) / cop},
)

datetimeindex = pd.date_range("1/1/2012", periods=24, freq="H")
datetimeindex = pd.date_range("1/1/2012", periods=24, freq="h")
energysystem = EnergySystem(timeindex=datetimeindex, infer_last_interval=True)
energysystem.add(
bcoal,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setup_class(cls):
timeindex=pandas.date_range(
"2016-01-01",
periods=cls.period,
freq="H",
freq="h",
),
infer_last_interval=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def test_connect_invest():
date_time_index = pd.date_range("1/1/2012", periods=24 * 7, freq="H")
date_time_index = pd.date_range("1/1/2012", periods=24 * 7, freq="h")

es = EnergySystem(timeindex=date_time_index, infer_last_interval=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_add_constraints_example(solver="cbc", nologg=False):
# ##### creating an oemof solph optimization model, nothing special here ##
# create an energy system object for the oemof solph nodes
es = EnergySystem(
timeindex=pd.date_range("1/1/2012", periods=4, freq="H"),
timeindex=pd.date_range("1/1/2012", periods=4, freq="h"),
infer_last_interval=True,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_gen_caes():
periods = len(data) - 1

# create an energy system
idx = pd.date_range("1/1/2017", periods=periods, freq="H")
idx = pd.date_range("1/1/2017", periods=periods, freq="h")
es = EnergySystem(timeindex=idx, infer_last_interval=True)

# resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_gen_chp():
periods = len(data) - 1

# create an energy system
idx = pd.date_range("1/1/2017", periods=periods, freq="H")
idx = pd.date_range("1/1/2017", periods=periods, freq="h")
es = solph.EnergySystem(timeindex=idx, infer_last_interval=True)

# resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_dispatch_fix_example(solver="cbc", periods=10):
inputs={bel: Flow(nominal_value=85, fix=data["demand_el"])},
)

datetimeindex = pd.date_range("1/1/2012", periods=periods, freq="H")
datetimeindex = pd.date_range("1/1/2012", periods=periods, freq="h")

energysystem = EnergySystem(
timeindex=datetimeindex, infer_last_interval=True
Expand Down
Loading

0 comments on commit 5b52583

Please sign in to comment.