Skip to content

Commit

Permalink
better from_speectrum behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
andycasey committed Jan 13, 2025
1 parent a66d78f commit 899990a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/astra/models/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ class Meta:

@classmethod
def from_spectrum(cls, spectrum, **kwargs):
return cls(
spectrum_pk=spectrum.spectrum_pk,
source_pk=spectrum.source_pk,
**kwargs
)

kwds = kwargs.copy()
given_source_pk = kwds.pop("source_pk", None)
given_spectrum_pk = kwds.pop("spectrum_pk", None)

if given_source_pk is not None and given_source_pk != spectrum.source_pk:
raise ValueError(f"`source_pk` mismatch between `spectrum` and `source_pk` argument ({spectrum.source_pk} != {given_source_pk})")
if given_spectrum_pk is not None and given_spectrum_pk != spectrum.spectrum_pk:
raise ValueError(f"`spectrum_pk` mismatch between `spectrum` and `spectrum_pk` argument ({spectrum.spectrum_pk} != {given_spectrum_pk})")

kwds.update({
"spectrum_pk": spectrum.spectrum_pk,
"source_pk": spectrum.source_pk,
})
return cls(**kwds)

0 comments on commit 899990a

Please sign in to comment.