pytest-ditto-polars 2.0.0rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ # tests/ci/.ditto and the root ditto.lock are pytest-ditto's own committed,
2
+ # PR-reviewed baseline (see docs/src/guides/lock-file.md), and each first-party
3
+ # plugin has its own under plugins/<name>/ — everywhere else .ditto/ditto.lock
4
+ # are ephemeral local test-run artifacts.
5
+ .ditto
6
+ !/tests/ci/.ditto/
7
+ !/plugins/*/tests/ci/.ditto/
8
+ ditto.lock
9
+ !/ditto.lock
10
+ !/plugins/*/ditto.lock
11
+ .tmp/
12
+ tmp.py
13
+ ditto-tui.html
14
+
15
+ # Python
16
+ __pycache__
17
+ # Written by the hatch-vcs build hook on every build and editable install.
18
+ src/ditto/_version.py
19
+ *.egg-info
20
+ *.pyc
21
+
22
+ # Testing
23
+ .pytest_cache
24
+ .pytest
25
+ .coverage
26
+ .hypothesis
27
+
28
+ # Linting
29
+ .ruff_cache
30
+
31
+ # IDE
32
+ .idea/
33
+ .vscode/
34
+ .claude/
35
+
36
+ # Build artifacts
37
+ dist/
38
+ archive/
39
+ docs/site/
40
+
41
+ # pixi environments
42
+ .pixi/*
43
+ !.pixi/config.toml
44
+
45
+ # Dev
46
+ .designs/
47
+ .issues/
48
+ .impl/
49
+ /tests/release/synthetic_plugin/build/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 pytest-ditto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.5
2
+ Name: pytest-ditto-polars
3
+ Version: 2.0.0rc1
4
+ Summary: pytest-ditto plugin for polars DataFrame snapshots.
5
+ Project-URL: Homepage, https://github.com/owlowlyowl/pytest-ditto
6
+ Project-URL: Source, https://github.com/owlowlyowl/pytest-ditto/tree/main/plugins/polars
7
+ Author-email: Lachlan Taylor <95459213+owlowlyowl@users.noreply.github.com>
8
+ Maintainer-email: Lachlan Taylor <95459213+owlowlyowl@users.noreply.github.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: polars,pytest,snapshot,testing
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Framework :: Pytest
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Testing
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: polars>=1.0
26
+ Requires-Dist: pytest-ditto<3,>=2.0.0rc1
27
+ Description-Content-Type: text/markdown
28
+
29
+ # pytest-ditto-polars
30
+
31
+ Extension plugin for [`pytest-ditto`](https://github.com/owlowlyowl/pytest-ditto) for `polars` DataFrame snapshots.
32
+
33
+ Use the following marks for their associated recorder:
34
+ - `@ditto.polars.parquet`
35
+ - `@ditto.polars.ipc`
36
+ - `@ditto.polars.csv`
37
+ - `@ditto.polars.ndjson`
38
+
39
+ Each mark is shorthand for `@ditto.record("polars.<format>")`.
40
+
41
+ ## Installation
42
+ ```bash
43
+ pip install pytest-ditto[polars]
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ import polars as pl
50
+ import polars.testing
51
+
52
+ import ditto
53
+
54
+
55
+ def awesome_fn_to_test(df: pl.DataFrame) -> pl.DataFrame:
56
+ return df.with_columns(pl.col("a") * 2)
57
+
58
+
59
+ # The following test uses polars.DataFrame.write_parquet to write the data snapshot
60
+ # to the `.ditto` directory with filename:
61
+ # `<module>.test_fn_with_parquet_dataframe_snapshot@ab_dataframe.polars.parquet`.
62
+
63
+
64
+ @ditto.polars.parquet
65
+ def test_fn_with_parquet_dataframe_snapshot(snapshot):
66
+ input_data = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
67
+ result = awesome_fn_to_test(input_data)
68
+ pl.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
69
+ ```
70
+
71
+ ### Format notes
72
+
73
+ Prefer `@ditto.polars.parquet`. It round-trips a DataFrame's values and dtypes.
74
+ The other formats are available when you need them, with these limits:
75
+
76
+ | Format | Values and dtypes |
77
+ |--------|-------------------|
78
+ | parquet | preserved |
79
+ | ipc | preserved; Polars marks `write_ipc` unstable, so snapshots can break across Polars versions |
80
+ | csv | re-inferred from text |
81
+ | ndjson | re-inferred from JSON |
82
+
83
+ **IPC** uses Polars' Arrow IPC writer. Polars documents `write_ipc` as
84
+ unstable, so a snapshot recorded on one Polars version may fail to load or
85
+ compare on another even if the DataFrame under test did not change.
86
+
87
+ **CSV** and **NDJSON** keep no type metadata, so dtypes are inferred again on
88
+ load. Frames of ints, floats, and strings round-trip in the plugin tests.
89
+ Do not use these formats for categoricals, enums, nested, or temporal columns.
@@ -0,0 +1,61 @@
1
+ # pytest-ditto-polars
2
+
3
+ Extension plugin for [`pytest-ditto`](https://github.com/owlowlyowl/pytest-ditto) for `polars` DataFrame snapshots.
4
+
5
+ Use the following marks for their associated recorder:
6
+ - `@ditto.polars.parquet`
7
+ - `@ditto.polars.ipc`
8
+ - `@ditto.polars.csv`
9
+ - `@ditto.polars.ndjson`
10
+
11
+ Each mark is shorthand for `@ditto.record("polars.<format>")`.
12
+
13
+ ## Installation
14
+ ```bash
15
+ pip install pytest-ditto[polars]
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```python
21
+ import polars as pl
22
+ import polars.testing
23
+
24
+ import ditto
25
+
26
+
27
+ def awesome_fn_to_test(df: pl.DataFrame) -> pl.DataFrame:
28
+ return df.with_columns(pl.col("a") * 2)
29
+
30
+
31
+ # The following test uses polars.DataFrame.write_parquet to write the data snapshot
32
+ # to the `.ditto` directory with filename:
33
+ # `<module>.test_fn_with_parquet_dataframe_snapshot@ab_dataframe.polars.parquet`.
34
+
35
+
36
+ @ditto.polars.parquet
37
+ def test_fn_with_parquet_dataframe_snapshot(snapshot):
38
+ input_data = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
39
+ result = awesome_fn_to_test(input_data)
40
+ pl.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
41
+ ```
42
+
43
+ ### Format notes
44
+
45
+ Prefer `@ditto.polars.parquet`. It round-trips a DataFrame's values and dtypes.
46
+ The other formats are available when you need them, with these limits:
47
+
48
+ | Format | Values and dtypes |
49
+ |--------|-------------------|
50
+ | parquet | preserved |
51
+ | ipc | preserved; Polars marks `write_ipc` unstable, so snapshots can break across Polars versions |
52
+ | csv | re-inferred from text |
53
+ | ndjson | re-inferred from JSON |
54
+
55
+ **IPC** uses Polars' Arrow IPC writer. Polars documents `write_ipc` as
56
+ unstable, so a snapshot recorded on one Polars version may fail to load or
57
+ compare on another even if the DataFrame under test did not change.
58
+
59
+ **CSV** and **NDJSON** keep no type metadata, so dtypes are inferred again on
60
+ load. Frames of ints, floats, and strings round-trip in the plugin tests.
61
+ Do not use these formats for categoricals, enums, nested, or temporal columns.
@@ -0,0 +1,30 @@
1
+ """Add the plugin's requirement on pytest-ditto to its dependencies.
2
+
3
+ Plugins are released in lockstep with pytest-ditto, from the same git tag, so each
4
+ requires at least the core it was released with: plugin X.Y.Z requires
5
+ ``pytest-ditto>=X.Y.Z,<3``. The local segment (``+sha`` on untagged commits) is
6
+ dropped because PEP 440 doesn't allow it in a ``>=`` specifier. ``<3`` is the plugin
7
+ contract's major version.
8
+
9
+ The plugin's other dependencies are listed under
10
+ ``[tool.hatch.metadata.hooks.custom]`` in its ``pyproject.toml``. A wheel built from
11
+ the sdist takes all of them from ``PKG-INFO`` and doesn't run this hook.
12
+
13
+ Every plugin carries an identical copy of this file, so it ships in each sdist.
14
+ """
15
+
16
+ from typing import Any
17
+
18
+ from hatchling.metadata.plugin.interface import MetadataHookInterface
19
+ from packaging.version import Version
20
+
21
+ CORE_MAJOR = 2
22
+
23
+
24
+ class CoreFloorHook(MetadataHookInterface):
25
+ def update(self, metadata: dict[str, Any]) -> None:
26
+ floor = Version(metadata["version"]).public
27
+ metadata["dependencies"] = [
28
+ f"pytest-ditto>={floor},<{CORE_MAJOR + 1}",
29
+ *self.config.get("dependencies", []),
30
+ ]
@@ -0,0 +1,72 @@
1
+ [project]
2
+ name = "pytest-ditto-polars"
3
+ dynamic = ["version", "dependencies"]
4
+ description = "pytest-ditto plugin for polars DataFrame snapshots."
5
+ keywords = ["pytest", "testing", "polars", "snapshot"]
6
+ authors = [{ name = "Lachlan Taylor", email = "95459213+owlowlyowl@users.noreply.github.com" }]
7
+ maintainers = [{ name = "Lachlan Taylor", email = "95459213+owlowlyowl@users.noreply.github.com" }]
8
+ requires-python = ">=3.12"
9
+ license = "MIT"
10
+ readme = "README.md"
11
+ classifiers = [
12
+ "Development Status :: 5 - Production/Stable",
13
+ "Framework :: Pytest",
14
+ "Intended Audience :: Developers",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Topic :: Software Development :: Testing",
17
+ "Programming Language :: Python",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Operating System :: OS Independent",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/owlowlyowl/pytest-ditto"
28
+ Source = "https://github.com/owlowlyowl/pytest-ditto/tree/main/plugins/polars"
29
+
30
+ [project.entry-points.ditto_recorders]
31
+ "polars.parquet" = "ditto_polars.recorders:parquet"
32
+ "polars.ipc" = "ditto_polars.recorders:ipc"
33
+ "polars.csv" = "ditto_polars.recorders:csv"
34
+ "polars.ndjson" = "ditto_polars.recorders:ndjson"
35
+
36
+
37
+ [build-system]
38
+ requires = ["hatchling"]
39
+ build-backend = "hatchling.build"
40
+
41
+
42
+ [tool.hatch.build]
43
+ targets.wheel.packages = ["src/ditto_polars"]
44
+ targets.sdist.only-include = ["src", "README.md", "LICENSE", "hatch_build.py"]
45
+
46
+ # hatch_build.py adds pytest-ditto>=<this version>,<3 to these.
47
+ [tool.hatch.metadata.hooks.custom]
48
+ dependencies = [
49
+ "polars>=1.0",
50
+ ]
51
+
52
+ # Versioned in lockstep with pytest-ditto, from the same git tag.
53
+ [tool.hatch.version]
54
+ source = "code"
55
+ path = "../../version_builder.py"
56
+ expression = "_version()"
57
+
58
+
59
+ [tool.pytest.ini_options]
60
+ minversion = "8.3"
61
+ testpaths = "tests/ci"
62
+ addopts = [
63
+ "-lv",
64
+ "--tb=short",
65
+ "--color=yes",
66
+ "--code-highlight=yes",
67
+ "--junit-xml=.pytest/test-results.xml",
68
+ ]
69
+ junit_family = "xunit2"
70
+ filterwarnings = [
71
+ "ignore::DeprecationWarning",
72
+ ]
@@ -0,0 +1,56 @@
1
+ import io
2
+
3
+ import polars as pl
4
+
5
+ from ditto.recorders import Recorder
6
+
7
+
8
+ __all__ = ("parquet", "ipc", "csv", "ndjson")
9
+
10
+
11
+ def _parquet_dumps(data: pl.DataFrame) -> bytes:
12
+ buffer = io.BytesIO()
13
+ data.write_parquet(buffer)
14
+ return buffer.getvalue()
15
+
16
+
17
+ def _parquet_loads(raw: bytes) -> pl.DataFrame:
18
+ return pl.read_parquet(raw)
19
+
20
+
21
+ parquet: Recorder[pl.DataFrame] = Recorder(dumps=_parquet_dumps, loads=_parquet_loads)
22
+
23
+
24
+ def _ipc_dumps(data: pl.DataFrame) -> bytes:
25
+ buffer = io.BytesIO()
26
+ data.write_ipc(buffer)
27
+ return buffer.getvalue()
28
+
29
+
30
+ def _ipc_loads(raw: bytes) -> pl.DataFrame:
31
+ return pl.read_ipc(raw)
32
+
33
+
34
+ ipc: Recorder[pl.DataFrame] = Recorder(dumps=_ipc_dumps, loads=_ipc_loads)
35
+
36
+
37
+ def _csv_dumps(data: pl.DataFrame) -> bytes:
38
+ return data.write_csv().encode("utf-8")
39
+
40
+
41
+ def _csv_loads(raw: bytes) -> pl.DataFrame:
42
+ return pl.read_csv(raw)
43
+
44
+
45
+ csv: Recorder[pl.DataFrame] = Recorder(dumps=_csv_dumps, loads=_csv_loads)
46
+
47
+
48
+ def _ndjson_dumps(data: pl.DataFrame) -> bytes:
49
+ return data.write_ndjson().encode("utf-8")
50
+
51
+
52
+ def _ndjson_loads(raw: bytes) -> pl.DataFrame:
53
+ return pl.read_ndjson(raw)
54
+
55
+
56
+ ndjson: Recorder[pl.DataFrame] = Recorder(dumps=_ndjson_dumps, loads=_ndjson_loads)