Skip to content

Commit

Permalink
Set pointer of DelayFixed to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
enekomartinmartinez committed Dec 18, 2023
1 parent 3b98bb9 commit 32c3da0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
24 changes: 24 additions & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
What's New
==========
v3.12.1 (2023/12/XX)
--------------------
New Features
~~~~~~~~~~~~

Breaking changes
~~~~~~~~~~~~~~~~

Deprecations
~~~~~~~~~~~~

Bug fixes
~~~~~~~~~
- Set the pointer of :py:class:`pysd.py_backend.statefuls.DelayFixed` to 0 during initialization (:issue:`427`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)

Documentation
~~~~~~~~~~~~~

Performance
~~~~~~~~~~~

Internal Changes
~~~~~~~~~~~~~~~~

v3.12.0 (2023/10/02)
--------------------
New Features
Expand Down
2 changes: 1 addition & 1 deletion pysd/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.12.0"
__version__ = "3.12.1"
3 changes: 3 additions & 0 deletions pysd/py_backend/statefuls.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ def initialize(self, init_val=None):
# The order can only be set once
self.order = round(order + SMALL_VENSIM)

# set the pointer to 0
self.pointer = 0

if init_val is None:
init_state_value = self.init_func()
else:
Expand Down
5 changes: 2 additions & 3 deletions tests/pytest_types/external/pytest_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ def test_read_clean_opyxl(self, _root):
Excels.clean()
assert list(Excels._Excels_opyxl) == []

@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="not working on Windows"
@pytest.mark.skip(
reason="may fail in parallel running"
)
def test_close_file(self, _root):
"""
Expand Down
17 changes: 17 additions & 0 deletions tests/pytest_types/statefuls/pytest_statefuls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import numpy as np
import xarray as xr

from pysd.py_backend.statefuls import Stateful, Integ, Delay, DelayN,\
Expand Down Expand Up @@ -96,6 +97,22 @@ def test_delay(self):
delay_c.initialize(6)
assert delay_c() == 6

for p, i in enumerate(np.arange(0, 2.5, 0.5)):
delay_c.update(None)
assert delay_c() == 6
assert delay_c.pointer == p+1

delay_c.update(None)
assert delay_c() == 5
assert delay_c.pointer == 0

# check that the pointer is set to 0 after initialization
delay_c.update(None)
assert delay_c.pointer != 0
delay_c.initialize()
assert delay_c.pointer == 0


def test_delay_subscript(self):
"""
Test for subscripted delay
Expand Down

0 comments on commit 32c3da0

Please sign in to comment.