Skip to content

Fix EasyList serialization issue and add test - #323

Merged
damskii9992 merged 11 commits into
developfrom
Issue321_EasyList_serialization
Oct 7, 2026
Merged

damskii9992 merged 11 commits into
developfrom
Issue321_EasyList_serialization

Conversation

@damskii9992

Copy link
Copy Markdown
Contributor

This PR fixes the issue described in #321

@damskii9992 damskii9992 added [scope] bug Bug report or fix (major.minor.PATCH) [priority] highest Urgent. Needs attention ASAP [area] serialization Anything related to serialization labels Oct 6, 2026
@damskii9992
damskii9992 requested a review from rozyczko October 6, 2026 12:40

@rozyczko rozyczko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of docstring changes muddling the actual code fix.
Anyway, there's a funcitonality deterioration for an edge case, so consider fixing it please.

) # noqa: E501
else:
protected_types = None
data_dicts = temp_dict.pop('data', None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing data key will now crash this.
EasyList pops with a default of None and then iterates over it. In the previous code a dict without data deserialized to an empty list. Here, it will raise TypeError. Maybe Use [] as the default?

data_dicts = temp_dict.pop('data', [])

This is how to show it:

from easyscience.base_classes.easy_list import EasyList

d = EasyList(unique_name='x').to_dict()
d.pop('data') 
EasyList.from_dict(d)

develop just returns an empty string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, is that really an issue? If the dict doesn't have a data key, then it isn't a serialized EasyList . . .
An empty EasyList will have an empty list in its data key.
I CAN change it, but do we want faulty dicts to properly deserialize?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably remove the default though. Better to fail with "missing key" error than "can't iterate over None" error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing inthe code builds an EasyList dict by hand, and to_dict always writes the key, so a missing data means the input is malformed. I guess failing is the right thing. But I would argue that KeyError is inconsistent. Every other bad input raises ValueError saying why the input is wrong. Let's be consistent.
something like

if 'data' not in temp_dict:
    raise ValueError("Serialized EasyList is missing the 'data' key.")
data_dicts = temp_dict.pop('data')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(+ the associated unit test)

Comment thread src/easyscience/fitting/sampler.py Outdated
fitter : Fitter
A configured ``Fitter`` (or ``MultiFitter``) whose minimizer has been
switched to ``AvailableMinimizers.Bumps``.
fitter : 'Fitter'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the quotes around Fitter correct? Will they render properly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. But it was also wrong before lol. I don't know what prettier did, but it changed stuff.
We need to do a proper overhaul of the EasyScience documentation sometime after the 3.0 release . . .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, never mind, it did change it for the worse . . .

an increment: to extend an existing chain of ``N`` raw
samples by ``M``, pass ``samples=N + M`` (DREAM keeps only
the last ``samples`` draws in its buffer). The
``Sampler.extend`` helper computes this for you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Smapler.extend be doubly backquoted? It was singly backquoted in the original.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the prettier changes . . .

@damskii9992
damskii9992 requested a review from rozyczko October 7, 2026 09:02

@rozyczko rozyczko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now.

@damskii9992

Copy link
Copy Markdown
Contributor Author

Will merge despite complaining linter. Sigh, we really need to get this linting updated . . .

@damskii9992 damskii9992 linked an issue Oct 7, 2026 that may be closed by this pull request
@damskii9992
damskii9992 merged commit 3025900 into develop Oct 7, 2026
24 of 26 checks passed
@damskii9992
damskii9992 deleted the Issue321_EasyList_serialization branch October 7, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[area] serialization Anything related to serialization [priority] highest Urgent. Needs attention ASAP [scope] bug Bug report or fix (major.minor.PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EasyList can't serialize/deserialize with ModelBase members

2 participants