pytest-ditto plugin for pandas DataFrame snapshots.
Project description
pytest-ditto-pandas
pytest-ditto plugin for pandas snapshots.
@ditto Marks
If the default recorder, pickle, isn't appropriate a different recorder can be
specified per test using ditto marks — customised pytest mark decorators.
Usage
pd.DataFrame
import pandas as pd
import ditto
def awesome_fn_to_test(df: pd.DataFrame):
df.loc[:, "a"] *= 2
return df
# The following test uses pandas.DataFrame.to_parquet to write the data snapshot to the
# `.ditto` directory with filename:
# `test_fn_with_parquet_dataframe_snapshot@ab_dataframe.pandas.parquet`.
@ditto.pandas.parquet
def test_fn_with_parquet_dataframe_snapshot(snapshot):
input_data = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
result = awesome_fn_to_test(input_data)
pd.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
# The following test uses pandas.DataFrame.to_json(orient="table") to write the data
# snapshot to the `.ditto` directory with filename:
# `test_fn_with_json_dataframe_snapshot@ab_dataframe.pandas.json`.
@ditto.pandas.json
def test_fn_with_json_dataframe_snapshot(snapshot):
input_data = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
result = awesome_fn_to_test(input_data)
pd.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
Format notes
| Format | Index preserved | dtype preserved |
|---|---|---|
| parquet | yes | yes |
| json | yes | yes |
| csv | single-level numeric or string only (see below) | no |
The CSV recorder does not preserve index type metadata. Supported index types
for round-trip are single-level numeric (note: RangeIndex is read back as
Int64) and string. DatetimeIndex, PeriodIndex, CategoricalIndex, and
MultiIndex are not supported — use @ditto.pandas.parquet or
@ditto.pandas.json for DataFrames with these index types.
When comparing a CSV snapshot with pd.testing.assert_frame_equal, pass
check_index_type=False to account for the RangeIndex → Int64 conversion.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_ditto_pandas-0.1.1.tar.gz.
File metadata
- Download URL: pytest_ditto_pandas-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
909c356905a063a7ad2403dec0052f45c510f40a3b03469e117dbf4dfb88f270
|
|
| MD5 |
6475c268ffa0eaadb68ed0bcb92f6506
|
|
| BLAKE2b-256 |
1ea74a3e65a6fc34749d9b87270f203aa08d0139b311f58c439642cda64f10d4
|
Provenance
The following attestation bundles were made for pytest_ditto_pandas-0.1.1.tar.gz:
Publisher:
release.yml on owlowlyowl/pytest-ditto-pandas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_ditto_pandas-0.1.1.tar.gz -
Subject digest:
909c356905a063a7ad2403dec0052f45c510f40a3b03469e117dbf4dfb88f270 - Sigstore transparency entry: 1155002689
- Sigstore integration time:
-
Permalink:
owlowlyowl/pytest-ditto-pandas@b353951527f4ebcdb3bd41d80c6e91c691fff09b -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/owlowlyowl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b353951527f4ebcdb3bd41d80c6e91c691fff09b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_ditto_pandas-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pytest_ditto_pandas-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
350b597e2f15027e5d9463ade1110947cfe3de414f6da38e3c1cdc59f310e0f2
|
|
| MD5 |
732d3855ebc9613a8948027a7a059a9a
|
|
| BLAKE2b-256 |
34b0547c7aed7ea2dcb959ac1a6aaf02c2c725629a5c766faca8ba0d0e44cc2f
|
Provenance
The following attestation bundles were made for pytest_ditto_pandas-0.1.1-py3-none-any.whl:
Publisher:
release.yml on owlowlyowl/pytest-ditto-pandas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_ditto_pandas-0.1.1-py3-none-any.whl -
Subject digest:
350b597e2f15027e5d9463ade1110947cfe3de414f6da38e3c1cdc59f310e0f2 - Sigstore transparency entry: 1155002691
- Sigstore integration time:
-
Permalink:
owlowlyowl/pytest-ditto-pandas@b353951527f4ebcdb3bd41d80c6e91c691fff09b -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/owlowlyowl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b353951527f4ebcdb3bd41d80c6e91c691fff09b -
Trigger Event:
release
-
Statement type: