Skip to main content

pytest-ditto plugin for pandas snapshots.

Project description

pytest-ditto-pandas

PyPI version Continuous Integration

pytest-ditto plugin for pandas snapshots.

@ditto Marks

If the default persistence format, pickle, isn't appropriate different formats can be specified per test by 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"))

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.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

pytest_ditto_pandas-0.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_ditto_pandas-0.0.1.tar.gz.

File metadata

  • Download URL: pytest_ditto_pandas-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pytest_ditto_pandas-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6c3d6d062ac42f99d7dc8663c9ec842f840c86837cc06e47ba03b6e986d133c5
MD5 6bf52921a5aed9de50a2dfc65a14d70b
BLAKE2b-256 0572451ded961ce7b3bd1ebda6b36e6f197e1b726277c0fdd4f2aa600f201467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_ditto_pandas-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65bed0703482495a76c44d6f0c531eae61bef01b75d750f021ac027ac259761a
MD5 a5568f969eb5f33525b4605b03412bc6
BLAKE2b-256 df2f3ce02e0d0d8094c4cc45cae316c215aacc27db052a5073f5d712587b7098

See more details on using hashes here.

Supported by

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