Skip to content

[bug] init_time_steps function in run_time_series.py module incorrectly skips tuples when creating range of values #2676

@ebalogun01

Description

@ebalogun01

Bug report checklis

  • Searched the issues page for similar reports

  • Read the relevant sections of the documentation

  • Browse the tutorials and tests for usefull code snippets and examples of use

  • Reproduced the issue after updating with pip install --upgrade pandapower (or git pull)

  • Tried basic troubleshooting (if a bug/error) like restarting the interpreter and checking the pythonpath

Reproducible Example

from pandapower.timeseries import run_time_series
import pandapower as pp


time_steps = (0, 2)
pp_net = pp.create_empty_network(sn_mva=_DEFAULT_PP_BASE_MVA)
run_time_series.run_timeseries(self.pp_net, time_steps=timesteps)

# When I run this it only provides results for 0 and 2 but skips 1. 
# The bug is here:


def init_time_steps(net, time_steps, **kwargs):
    # initializes time steps if as a range
    if not isinstance(time_steps, Iterable):
        if isinstance(time_steps, tuple):
            time_steps = range(time_steps[0], time_steps[1])
        elif time_steps is None and ("start_step" in kwargs and "stop_step" in kwargs):
            logger.warning("start_step and stop_step are depricated. "
                           "Please use a tuple like time_steps = (start_step, stop_step) instead or a list")
            time_steps = range(kwargs["start_step"], kwargs["stop_step"] + 1)
        else:
            logger.warning("No time steps to calculate are specified. "
                           "I'll check the datasource of the first controller for avaiable time steps")
            ds = net.controller.object.at[0].data_source
            if ds is None:
                raise UserWarning("No time steps are specified and the first controller doesn't have a data source"
                                  "the time steps could be retrieved from")
            else:
                max_timestep = ds.get_time_steps_len()
            time_steps = range(max_timestep)
    return time_steps

Issue Description and Traceback

Timeseries module fails to create correct range when specified (start, stop) tuple and instead uses the tuple as the range, skipping actual intermediate values in the range. For example (0, 2) skips position 1 even though we expected it to include (0, 1, 2) which is equivalent to range(start, stop+1). I expect this to fail with range (0, 5) as well because it will simply return (0, 5) and skip the intermediate time steps.

Expected Behavior

Expected behavior would be to write solutions for all time steps. The line that checks if tuple is Iterable is the bug, and need to be adjusted.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5cf90477d3503834d983f69350f250a6ff7
python : 3.11.9
python-bits : 64
OS : Linux
OS-release : 6.12.27-1rodete1-amd64
Version : #1 SMP PREEMPT_DYNAMIC Debian 6.12.27-1rodete1 (2025-05-19)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 2.2.5
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.1.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 5.4.0
matplotlib : None
numba : 0.61.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

Label

  • Relevant labels are selected

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions