|
| 1 | +# Diffly |
| 2 | + |
| 3 | +A utility package for comparing Polars DataFrames. |
| 4 | + |
| 5 | +```{toctree} |
| 6 | +:maxdepth: 2 |
| 7 | +:hidden: |
| 8 | +
|
| 9 | +guides/index |
| 10 | +API Reference <api/modules> |
| 11 | +``` |
| 12 | + |
| 13 | +## What is Diffly? |
| 14 | + |
| 15 | +Diffly is a utility package for comparing Polars DataFrames and LazyFrames with detailed analysis capabilities. It identifies differences between datasets including: |
| 16 | + |
| 17 | +- **Schema differences**: Columns that exist only in one DataFrame |
| 18 | +- **Row-level mismatches**: Rows that are different between DataFrames |
| 19 | +- **Missing rows**: Rows that exist only in one DataFrame |
| 20 | +- **Column value changes**: Detailed analysis of which columns differ and by how much |
| 21 | + |
| 22 | +## Key Features |
| 23 | + |
| 24 | +- **Primary key-based comparison**: Join DataFrames on specified primary keys for row-by-row comparison |
| 25 | +- **Tolerance-based equality**: Configure absolute and relative tolerances for floating point comparisons |
| 26 | +- **Temporal tolerance**: Support for comparing temporal types (dates, datetimes) with configurable tolerances |
| 27 | +- **Rich summaries**: Generate detailed, visually formatted comparison reports |
| 28 | +- **Lazy evaluation**: Uses Polars LazyFrames internally for efficient computation |
| 29 | +- **Method caching**: Automatically caches comparison results to avoid recomputation |
| 30 | +- **Per-column tolerances**: Fine-grained control over comparison tolerances for each column |
| 31 | +- **Testing utilities**: Built-in assertion functions for DataFrame and Collection equality in tests |
| 32 | + |
| 33 | +## Quick Example |
| 34 | + |
| 35 | +```python |
| 36 | +import polars as pl |
| 37 | +from diffly import compare_frames |
| 38 | + |
| 39 | +# Create two DataFrames to compare |
| 40 | +left = pl.DataFrame({ |
| 41 | + "id": ["a", "b", "c"], |
| 42 | + "value": [1.0, 2.0, 3.0], |
| 43 | + "category": ["x", "y", "z"] |
| 44 | +}) |
| 45 | + |
| 46 | +right = pl.DataFrame({ |
| 47 | + "id": ["a", "b", "d"], |
| 48 | + "value": [1.0, 2.1, 4.0], |
| 49 | + "category": ["x", "y", "w"] |
| 50 | +}) |
| 51 | + |
| 52 | +# Compare the DataFrames |
| 53 | +comparison = compare_frames(left, right, primary_key="id") |
| 54 | + |
| 55 | +# Check if they're equal |
| 56 | +if not comparison.equal(): |
| 57 | + # Display a detailed summary |
| 58 | + summary = comparison.summary( |
| 59 | + show_perfect_column_matches=True, |
| 60 | + top_k_column_changes=5 |
| 61 | + ) |
| 62 | + print(summary) |
| 63 | +``` |
| 64 | + |
| 65 | +## Next Steps |
| 66 | + |
| 67 | +- Follow the [Quickstart Guide](guides/quickstart.md) for a comprehensive introduction |
| 68 | +- Explore [Examples](guides/examples/index.md) for common use cases |
| 69 | +- Learn about advanced [Features](guides/features/index.md) like tolerances and custom summaries |
| 70 | +- Check the [API Reference](api/modules.rst) for detailed function documentation |
0 commit comments