You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be very useful if the dataframe_regression fixture could check non-numeric columns in dataframes.
One simple work around is to use data_regression and convert the dataframe to a dictionary:
data_regression.check(df.to_dict("records"))
However, this does not allow application of tolerances to numerical values.
As a workaround, I am currently defining a fixture in my conftest.py that leverages data_regression for the non-numeric columns and dataframe_regression for the numeric columns (with tolerances):
# conftest.py@pytest.fixture()defcheck_df(dataframe_regression, data_regression):
"""Fixture to check dataframe against expected values leveraging pytest-regression dataframe_regression and data_regression fixtures. This fixture allows verification of non-numeric columns as well as application of tolerances on numeric columns."""defcheck(df, basename=None, fullpath=None, tolerances=None, default_tolerance=None):
data_regression.check(
df.select_dtypes(exclude="number").to_dict("records"),
basename=basename,
fullpath=fullpath,
)
dataframe_regression.check(
df.select_dtypes(include="number"),
basename=basename,
fullpath=fullpath,
tolerances=tolerances,
default_tolerance=default_tolerance,
)
yieldcheck# test_something.pydeftest_something(check_df):
df=some_operation()
check_df(df, default_tolerance=dict(atol=1e-8, rtol=1e-5)
While this works, it is less elegant and requires to be run twice to generate the yaml and csv files of expected results.
The text was updated successfully, but these errors were encountered:
It would be very useful if the
dataframe_regression
fixture could check non-numeric columns in dataframes.One simple work around is to use
data_regression
and convert the dataframe to a dictionary:However, this does not allow application of tolerances to numerical values.
As a workaround, I am currently defining a fixture in my
conftest.py
that leveragesdata_regression
for the non-numeric columns anddataframe_regression
for the numeric columns (with tolerances):While this works, it is less elegant and requires to be run twice to generate the
yaml
andcsv
files of expected results.The text was updated successfully, but these errors were encountered: