Skip to main content

pytest-ditto plugin for pandas DataFrame snapshots.

Project description

pytest-ditto-pandas

PyPI version Continuous Integration

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 RangeIndexInt64 conversion.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_ditto_pandas-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_ditto_pandas-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

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

Hashes for pytest_ditto_pandas-0.1.1.tar.gz
Algorithm Hash digest
SHA256 909c356905a063a7ad2403dec0052f45c510f40a3b03469e117dbf4dfb88f270
MD5 6475c268ffa0eaadb68ed0bcb92f6506
BLAKE2b-256 1ea74a3e65a6fc34749d9b87270f203aa08d0139b311f58c439642cda64f10d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_ditto_pandas-0.1.1.tar.gz:

Publisher: release.yml on owlowlyowl/pytest-ditto-pandas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_ditto_pandas-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_ditto_pandas-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 350b597e2f15027e5d9463ade1110947cfe3de414f6da38e3c1cdc59f310e0f2
MD5 732d3855ebc9613a8948027a7a059a9a
BLAKE2b-256 34b0547c7aed7ea2dcb959ac1a6aaf02c2c725629a5c766faca8ba0d0e44cc2f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page