Skip to main content

pandas integration for inline-snapshot

Project description

ci Docs pypi version Python Versions PyPI - Downloads coverage GitHub Sponsors

Installation

This project is currently only available for insiders, which mean that you can get access to it if you sponsor me. You should then have access to this repository.

pip install git+ssh://git@github.com:15r10nk-insiders/inline-snapshot-pandas.git@insiders

Usage

This packages provides special assert_(frame|series|index)_equal implementation which accept a snapshot as second argument.

from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(df, snapshot())
pytest --inline-snapshot=create
from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(
        df,
        snapshot(DataFrame([{"col0": 1}, {"col0": 2}])),
    )

Another way to use it is to call setup() in conftest.py, which replaces the implementation which pandas uses.

from inline_snapshot_pandas import setup

setup()

You can then use implementation from pandas with snapshots.

from pandas import DataFrame
from pandas.testing import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2], "col1": [1, 5j], "col3": ["a", "b"]})

    # the second argument can be a snapshot
    assert_frame_equal(
        df,
        snapshot(
            DataFrame(
                [
                    {"col0": 1, "col1": (1 + 0j), "col3": "a"},
                    {"col0": 2, "col1": 5j, "col3": "b"},
                ]
            )
        ),
    )

Usage for non-insiders

The version which is currently available on pip provides functions which can be used by non insiders. They provides a special snapshot function which is implemented as lambda value: value and can be used with the normal assert_*_equal functions of pandas.

The following code can be executed with the insider an non-insider version:

from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal

# importing snapshot from inline_snapshot_pandas is important
from inline_snapshot_pandas import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(
        df,
        snapshot(DataFrame([{"col0": 1}, {"col0": 2}])),
    )

Issues

If you encounter any problems, please report an issue along with a detailed description.

License

Distributed under the terms of the MIT license, "inline-snapshot-pandas" is free and open source software.

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

inline_snapshot_pandas-0.1.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

inline_snapshot_pandas-0.1.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file inline_snapshot_pandas-0.1.0.tar.gz.

File metadata

File hashes

Hashes for inline_snapshot_pandas-0.1.0.tar.gz
Algorithm Hash digest
SHA256 51ec02e90c64422d4d3ba7b503e9fcfb64a6e69a80f07176c3a45d62d3142b21
MD5 a114196ea7445b4957dd2a1f0ac3bfb7
BLAKE2b-256 447011263e148c95066020753bfbb4ca9d3d582536df7893eabf018999f7285a

See more details on using hashes here.

File details

Details for the file inline_snapshot_pandas-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for inline_snapshot_pandas-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0be71f0ea4def575e96431a6acdc5fdd114ee8d6bc77ca45c5ae4271196dc20c
MD5 947833d8e46f7c704e357c250edf1a90
BLAKE2b-256 50ca81daf40f819ef53ee8300849868e14aed35bdaf9d9502a992bbf6d6bfede

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