Skip to content

Commit 9333fd8

Browse files
committed
fixed union method
1 parent 6f48867 commit 9333fd8

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

RATapi/classlist.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,14 @@ def union(self, other: Sequence[T]) -> None:
295295
"""Extend the ClassList by a sequence, ignoring input items with names that already exist."""
296296
if other and not (isinstance(other, Sequence) and not isinstance(other, str)):
297297
other = [other]
298-
if hasattr(other, self.name_field):
299-
other = (item for item in other if getattr(other, self.name_field) not in self.get_names())
300298

301-
self.extend(other)
299+
self.extend(
300+
[
301+
item
302+
for item in other
303+
if hasattr(item, self.name_field) and getattr(item, self.name_field) not in self.get_names()
304+
]
305+
)
302306

303307
def set_fields(self, index: int, **kwargs) -> None:
304308
"""Assign the values of an existing object's attributes using keyword arguments."""

RATapi/utils/orso.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from orsopy.fileio import load_orso
88

99
from RATapi import ClassList, Project
10-
from RATapi.models import AbsorptionLayer, Background, Contrast, Data, Layer, Parameter, Resolution
10+
from RATapi.models import AbsorptionLayer, Contrast, Data, Layer, Parameter, Resolution
1111

1212

1313
def load_ort_data(filepath: str) -> Union[Data, list[Data]]:
@@ -167,12 +167,13 @@ def orso_model_to_rat(model: orsopy.fileio.model_language.SampleModel | str, abs
167167
parameters.union(layer_params)
168168
layers.union(layer)
169169

170-
171-
return ORSOSample(bulk_in=bulk_in,
172-
bulk_out=bulk_out,
173-
parameters=parameters,
174-
layers=layers,
175-
model=[layer.material.formula for layer in stack[1:-1]])
170+
return ORSOSample(
171+
bulk_in=bulk_in,
172+
bulk_out=bulk_out,
173+
parameters=parameters,
174+
layers=layers,
175+
model=[layer.material.formula for layer in stack[1:-1]],
176+
)
176177

177178

178179
def orso_layer_to_rat_layer(

0 commit comments

Comments
 (0)