This release is a pre-release and may not be stable for production use.
pytest-ditto-pandas
Extension plugin for pytest-ditto for pandas DataFrame snapshots.
Use the following marks for their associated recorder:
@ditto.pandas.parquet@ditto.pandas.json@ditto.pandas.csv
Each mark is shorthand for @ditto.record("pandas.<format>").
Installation
pip install pytest-ditto[pandas]
Usage
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:
# `<module>.test_fn_with_parquet_dataframe_snapshot@ab_dataframe~<hash>.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:
# `<module>.test_fn_with_json_dataframe_snapshot@ab_dataframe~<hash>.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
Only parquet round-trips a DataFrame exactly. JSON and CSV change some values or types on the way through, and a snapshot comparison then fails even though the code under test didn't change.
| Format | Index | Values and dtypes |
|---|---|---|
| parquet | preserved | preserved |
| json | preserved, except an index named index |
preserved, except numeric widths |
| csv | single-level only; values re-parsed | re-parsed from text |
JSON (to_json(orient="table")):
- An index named
indexis read back unnamed, and pandas warns that the name is not round-trippable. - Numeric columns are widened to 64 bits, so
int8,int32anduint16come back asint64, andfloat32asfloat64.
CSV keeps no type information, so every column and the index are parsed from text on load:
- Strings that look like numbers become numbers:
"001"is read back as1. - Strings pandas treats as missing, such as
"NA","null"and"", becomeNaN. - dtypes are inferred again, so
int32comes back asint64, and categoricals come back as plain strings. - Only a single-level index is supported.
DatetimeIndex,PeriodIndex,CategoricalIndexandMultiIndexare not. - A
RangeIndexmay come back as a plain integer index, depending on the pandas version. Passcheck_index_type=Falsetopd.testing.assert_frame_equalto allow for that. It does not help with any of the changed values above.
Use @ditto.pandas.parquet for DataFrames that hit any of these cases.
Metadata
Release files for pytest-ditto-pandas 2.0.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_ditto_pandas-2.0.0rc1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_ditto_pandas-2.0.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / pytest_ditto_pandas-2.0.0rc1.tar.gz
| Download URL | pytest_ditto_pandas-2.0.0rc1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d71672535521f416915768110a927db9b4dd1e145e9e5aa4d127fd23b31f29cd
|
|
BLAKE2b-256 checksum How to use checksums |
d04f25213c46f35ce81c47158effffb865ee2d86c1d5f8a5613e02e595f09c2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / pytest_ditto_pandas-2.0.0rc1-py3-none-any.whl
| Download URL | pytest_ditto_pandas-2.0.0rc1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a715405f8f6799af74db60e8d1fc057f3c5e76849377c92eed7feb4a2992baf
|
|
BLAKE2b-256 checksum How to use checksums |
619a48f7895952502d62eb2db579911403f7f53fbf797693bced6200ebe8cd09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency log