pandas integration for inline-snapshot (insider only)
Project description
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
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
Hashes for inline_snapshot_pandas-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2ac3e7b2a611c2483a72f2da61d796a75821d4c7b4abaaa30238e14963c579 |
|
MD5 | a28dc1315dc421931324ed8d2d4cec50 |
|
BLAKE2b-256 | df73b5f85599610e9391831b1963e60130a7830716aee9748b7567e1700668c1 |
Hashes for inline_snapshot_pandas-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f87180bd73803191cef59a1b6265527c973d36f68ea041389db0566c0c0f2a36 |
|
MD5 | 4f2f0118921e8a5764a327ab6995cb6d |
|
BLAKE2b-256 | 2c367196c229b105c865916f2be72c55c5998fb70854aa76d480486a6a15640b |