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

support dill/pickle #15

Merged
merged 1 commit into from
Dec 11, 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
7 changes: 7 additions & 0 deletions dummio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from dummio import json as json
from dummio import pickle as pickle
from dummio import text as text

try:
Expand All @@ -23,3 +24,9 @@
except ImportError:
# this would require the optional dependency pydantic
pass

try:
from dummio import dill as dill
except ImportError:
# this would require the optional dependency dill
pass
19 changes: 19 additions & 0 deletions dummio/dill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""IO for dill."""

from typing import Any

import dill

from dummio.constants import PathType


def save(data: Any, *, filepath: PathType) -> None:
"""Save a dill file."""
with open(filepath, "wb") as file:
dill.dump(data, file)


def load(filepath: PathType) -> Any:
"""Read a dill file."""
with open(filepath, "rb") as file:
return dill.load(file)
18 changes: 18 additions & 0 deletions dummio/pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""IO for pickle."""

import pickle
from typing import Any

from dummio.constants import PathType


def save(data: Any, *, filepath: PathType) -> None:
"""Save a pickle file."""
with open(filepath, "wb") as file:
pickle.dump(data, file)


def load(filepath: PathType) -> Any:
"""Read a pickle file."""
with open(filepath, "rb") as file:
return pickle.load(file)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dummio"
version = "1.3.0"
version = "1.4.0"
description = "Easiest-possible IO for basic file types."
authors = [{ name = "Zach Kurtz", email = "[email protected]" }]
readme = "README.md"
Expand All @@ -21,6 +21,7 @@ extras = [
"pyyaml>=6.0.2",
"onnx>=1.10.1",
"pydantic>=2.10.2",
"dill>=0.2.2",
]

[project.urls]
Expand Down
18 changes: 18 additions & 0 deletions tests/test_all_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ def test_yaml(tmp_path: Path) -> None:
data=dictionary(),
module=dummio.yaml,
)


def test_pickle(tmp_path: Path) -> None:
"""Test the packio package."""
_assert_cycle(
path=tmp_path / "data.pkl",
data=dictionary(),
module=dummio.pickle,
)


def test_dill(tmp_path: Path) -> None:
"""Test the packio package."""
_assert_cycle(
path=tmp_path / "data.pkl",
data=dictionary(),
module=dummio.dill,
)
2 changes: 2 additions & 0 deletions tests/test_assert_module_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from dummio.protocol import assert_module_protocol

IO_MODULES = [
"dummio.dill",
"dummio.json",
"dummio.onnx",
"dummio.pickle",
"dummio.pydantic",
"dummio.text",
"dummio.yaml",
Expand Down
13 changes: 12 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading