Skip to content

Commit

Permalink
Merge pull request #15 from zkurtz/add-pickle
Browse files Browse the repository at this point in the history
support dill/pickle
  • Loading branch information
zkurtz authored Dec 11, 2024
2 parents b8ebb4f + dc7585a commit 1738845
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 2 deletions.
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.

0 comments on commit 1738845

Please sign in to comment.