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

Migrated the PyYAML update from FASTsim #98

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies = [
"polars==0.20.25",
"pyarrow",
"requests",
"PyYAML==6.0.2",
]

[project.urls]
Expand Down
13 changes: 9 additions & 4 deletions python/altrios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ def to_pydict(self) -> Dict:
"""
Returns self converted to pure python dictionary with no nested Rust objects
"""
import json
return json.loads(self.to_json())
from yaml import load
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
pydict = load(self.to_yaml(), Loader = Loader)
return pydict

@classmethod
def from_pydict(cls, pydict: Dict) -> Self:
"""
Instantiates Self from pure python dictionary
"""
import json
return cls.from_json(json.dumps(pydict))
import yaml
return cls.from_yaml(yaml.dump(pydict),skip_init=False)

def to_dataframe(self, pandas:bool=False) -> [pd.DataFrame, pl.DataFrame, pl.LazyFrame]:
"""
Expand Down
Loading