Skip to content

Commit

Permalink
Merge branch 'develop' into weakref
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Sep 10, 2024
2 parents 2faeebf + 8e15ea6 commit 9da9e48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ MontePy Changelog
#Next Version#
--------------

**Bug Fixes**

* Fixed a bug where ``problem.materials.append_renumber`` would double add a material to ``problem.data_inputs`` (:issue:`516`).

**Performance Improvement**

* Fixed method of linking ``Material`` to ``ThermalScattering`` objects, avoiding a very expensive O(N:sup:`2`) (:issue:`510`).
Expand Down
2 changes: 1 addition & 1 deletion montepy/numbered_object_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def append(self, obj, insert_in_data=True):
:type insert_in_data: bool
:raises NumberConflictError: if this object has a number that is already in use.
"""
super().append(obj)
if self._problem:
if self._last_index:
index = self._last_index
Expand All @@ -452,7 +453,6 @@ def append(self, obj, insert_in_data=True):
if insert_in_data:
self._problem.data_inputs.insert(index + 1, obj)
self._last_index = index + 1
super().append(obj)

def __delitem__(self, idx):
if not isinstance(idx, int):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_numbered_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,38 @@ def test_data_append(cp_simple_problem):
prob.materials.append(new_mat)
assert new_mat in prob.materials
assert new_mat in prob.data_inputs
assert prob.data_inputs.count(new_mat) == 1
# trigger getting data_inputs end
prob.materials.clear()
prob.materials.append(new_mat)
assert new_mat in prob.materials
assert new_mat in prob.data_inputs
assert prob.data_inputs.count(new_mat) == 1
prob.data_inputs.clear()
prob.materials._last_index = None
new_mat = copy.deepcopy(next(iter(prob.materials)))
new_mat.number = prob.materials.request_number()
prob.materials.append(new_mat)
assert new_mat in prob.materials
assert new_mat in prob.data_inputs
assert prob.data_inputs.count(new_mat) == 1
# trigger getting index of last material
prob.materials._last_index = None
new_mat = copy.deepcopy(next(iter(prob.materials)))
new_mat.number = prob.materials.request_number()
prob.materials.append(new_mat)
assert new_mat in prob.materials
assert new_mat in prob.data_inputs
assert prob.data_inputs.count(new_mat) == 1


def test_data_append_renumber(cp_simple_problem):
prob = cp_simple_problem
new_mat = copy.deepcopy(next(iter(prob.materials)))
prob.materials.append_renumber(new_mat)
assert new_mat in prob.materials
assert new_mat in prob.data_inputs
assert prob.data_inputs.count(new_mat) == 1


def test_data_remove(cp_simple_problem):
Expand Down

0 comments on commit 9da9e48

Please sign in to comment.