Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement basic save and load functionality #53

Closed
wants to merge 8 commits into from

Conversation

orionarcher
Copy link
Collaborator

@orionarcher orionarcher commented Dec 21, 2021

Description

Addresses issue #52

This PR seeks to implement basic functionality to serialize the key data in a Solution and then reconstitute it as a dict. This allows the main features of a Solution to be saved.

Todos

Notable points that this PR has either accomplished or will accomplish.

  • implement Solution.load_json
  • implement Solution.save_json
  • clean up code
  • finalize API

Status

  • Ready to go

@pep8speaks
Copy link

Hello @orioncohen! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 471:20: W292 no newline at end of file

@hmacdope
Copy link
Member

You can use .__dict__() to compare internal state of two classes as dictionaries, might help in your comparisons.

}
return data

def as_dict(self):
Copy link
Member

Choose a reason for hiding this comment

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

This seems quite indirect -- why not have a to_dict, from_dict akin to a __setstate__, __getstate__ method?

save_json is also not my favourite method name. to_json could return a json string perhaps (json.dumps(obj.to_dict())), which the user could be responsible for writing to a file, or a to/from_file method could handle that.

With a bunch of common mis-matching APIs already out there (e.g. pandas.to_json, pandas.read_json; pydantic's .json(), .parse_raw/ .parse_file) keeping a neat to/from naming scheme is really valuable.

@orionarcher orionarcher added the enhancement New feature or request label Jul 15, 2022
@orionarcher orionarcher self-assigned this Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants