## diff_table()


Compare two tables value by value.


Usage

``` python
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"`, `x` is the benchmark: `y` is cast to its column types and `y`'s extra columns are dropped. In `mode="equal"` the tables must have the same columns with the same types.

`y: pd.DataFrame`  
The tables. In `mode="benchmark"`, `x` is the benchmark: `y` is cast to its column types and `y`'s extra columns are dropped. In `mode="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 `by` given, 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](DiffWarning.md#dazdiff.DiffWarning); a name `by` or `measures` also names is an error.

`row_key: str = ``"none"`  
`"none"` (default), or a virtual `row_number` key 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 with `by`.

`measures: Sequence[str] | str = ``"numeric"`  
`"numeric"` (float columns), `"numeric+integer"`, or column names.

`tolerance: float = ``0.0`  
For a finite pair, a value is `same` when `abs_diff <= tolerance` or `rel_diff <= rel_tol`.

`rel_tol: float = ``0.0`  
For a finite pair, a value is `same` when `abs_diff <= tolerance` or `rel_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 `y` to `x`'s types. `None` (default) casts in benchmark mode; `False` requires the types to agree. Equal mode never casts, so `cast=True` with it is an error. A number cast to text is written with the decimals `x` uses, when every value of `x`'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, with `metric`, `row_id_x`, `row_id_y`, `value_x`, `value_y`, `diff`, `abs_diff`, `rel_diff` and `status`. With `duplicates="aggregate"` (`"groups"`), one row per key and measure, with `n_rows_x`, `n_rows_y`, `values_x` and `values_y` (sorted tuples). With no measures (`"rows"`), one row per source row, with `key_seq`. `attrs` also holds `mode`, `by`, `measures`, `tolerance`, `name_map`, `dropped`, `excluded`, `ignored` and `truncated`.


## 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.
