diff_table()
Compare two tables value by value.
Usage
diff_table(
x,
y,
*,
mode="benchmark",
by=None,
exclude=None,
row_key="none",
measures="numeric",
tolerance=0.0,
rel_tol=0.0,
duplicates="disambiguate",
cast=None,
truncate=True
)Parameters
x: pd.DataFrame-
The tables. In
mode="benchmark",xis the benchmark:yis cast to its column types andy’s extra columns are dropped. Inmode="equal"the tables must have the same columns with the same types. y: pd.DataFrame-
The tables. In
mode="benchmark",xis the benchmark:yis cast to its column types andy’s extra columns are dropped. Inmode="equal"the tables must have the same columns with the same types. mode: str = "benchmark"-
"benchmark"(default) or"equal". by: Sequence[str] | str | None = None-
Key columns that identify a row. Defaults to every column that is not a measure. With
bygiven, other non-measure columns are ignored with a note in benchmark mode, and are an error in equal mode. exclude: Sequence[str] | str | None = None-
Columns, in either spelling, removed from both tables before anything else, in either mode. They need not be in both tables and are not announced as dropped or ignored. A name in neither table is a DiffWarning; a name
byormeasuresalso names is an error. row_key: str = "none"-
"none"(default), or a virtualrow_numberkey added to the identity:"position"numbers rows as they come,"sorted"numbers them after sorting both tables by their compared columns. Use it when every column is a measure. It cannot be combined withby. measures: Sequence[str] | str = "numeric"-
"numeric"(float columns),"numeric+integer", or column names. tolerance: float = 0.0-
For a finite pair, a value is
samewhenabs_diff <= toleranceorrel_diff <= rel_tol. rel_tol: float = 0.0-
For a finite pair, a value is
samewhenabs_diff <= toleranceorrel_diff <= rel_tol. duplicates: str = "disambiguate"-
"disambiguate"(default) pairs repeated keys in arrival order, with a warning;"aggregate"compares the multiset of values per key and measure (tolerances must be 0);"error"refuses repeated keys. cast: bool | None = None-
Whether to cast the compared columns of
ytox’s types.None(default) casts in benchmark mode;Falserequires the types to agree. Equal mode never casts, socast=Truewith it is an error. A number cast to text is written with the decimalsxuses, when every value ofx’s column uses the same number of them. truncate: bool = True- Allow truncating non-integral values when casting to an integer column.
Returns
pandas.DataFrame-
Sorted by the key. With measures (
attrs["shape"] == "cells"), one row per key and measure, withmetric,row_id_x,row_id_y,value_x,value_y,diff,abs_diff,rel_diffandstatus. Withduplicates="aggregate"("groups"), one row per key and measure, withn_rows_x,n_rows_y,values_xandvalues_y(sorted tuples). With no measures ("rows"), one row per source row, withkey_seq.attrsalso holdsmode,by,measures,tolerance,name_map,dropped,excluded,ignoredandtruncated.
Raises
DiffError- When the question cannot be answered: missing columns, type differences in equal mode, clashing names, no key, or no key in common.
Warns
DiffWarning-
When the answer may be wrong: repeated keys paired by arrival order.
DiffNote- For expected side effects: dropped or ignored columns, truncation, no measures.