FireDucks Documentation

repository·main·Indexed 21 days ago

https://github.com/fireducks-dev/fireducks

FireDucks is a high-performance, compiler-accelerated dataframe library for Python designed as a fast, drop-in replacement for pandas. It features a JIT compiler for query planning and optimization, supporting lazy execution and method chaining to improve performance on large-scale data analysis. It can be integrated into existing workflows via an import hook or the `fireducks.pandas` module, and provides a `%%fireducks.profile` magic command for Jupyter notebooks.

Tokens
5.1K
Snippets
27
Records
29
Agent score
73%

What's inside FireDucks

  1. Overview of FireDucks

    main
    FireDucks is a high-performance, compiler-accelerated dataframe library for Python. It is designed for speed while maintaining compatibility with the pandas API. It is particularly effective at query planning and optimization for large-scale data analysis.
  2. Use the FireDucks Import Hook

    main

    The Import Hook allows you to use FireDucks without modifying your source code. It automatically replaces import pandas statements with FireDucks throughout your execution environment. This is ideal for existing programs or when using external libraries (like matplotlib) that might internally use pandas.

    For Python scripts: Run your script using the -m option with the fireducks.pandas module.

    For IPython/Jupyter Notebooks: Use the %load_ext magic command to activate the hook before importing pandas.

    # For scripts
    python3 -m fireducks.pandas your_script.py
    # For Jupyter/IPython
    %load_ext fireducks.pandas
    import pandas as pd
  3. Profile FireDucks performance with %%fireducks.profile

    main

    Use the %%fireducks.profile magic command in a Jupyter cell to profile the execution of your code. This is useful for observing the performance benefits of FireDucks' optimizations like Common Sub-expression Elimination, Dead Code Elimination, and Pushdown operations.

    %%fireducks.profile
    # Your pandas code here
    df.groupby("A").sum()
  4. Enable FireDucks in Jupyter Notebooks

    main

    To use FireDucks as a drop-in replacement for pandas in a Jupyter environment, load the fireducks.pandas extension. This allows you to use standard import pandas as pd syntax while benefiting from FireDucks' lazy execution and optimizations.

    %load_ext fireducks.pandas
    import numpy as np
    import pandas as pd
  5. Use Explicit Import for FireDucks

    main

    If you prefer to be explicit, you can use the fireducks.pandas module directly. To switch an existing pandas-based program to FireDucks, replace your import pandas statement with import fireducks.pandas.

    # Replace this:
    # import pandas as pd
    
    # With this:
    import fireducks.pandas as pd
  6. Install FireDucks via pip

    main

    FireDucks is available for Linux (manylinux) on the x86_64 architecture. You can install it using pip.

    Requirements:

    • Python version: 3.9 to 3.13 (Note: Python 3.8 is no longer supported as of FireDucks 1.1.0 due to pyarrow 18.0.0 dependency).

    If you use a Python version outside this range, you may encounter the error: "No matching distribution found for fireducks".

    pip install fireducks
  7. Optimize queries using method chaining

    main

    To achieve maximum performance benefits from the FireDucks JIT compiler, use method chaining for your queries.

    When you write a query as a single chained expression, the compiler can optimize the entire data flow because it knows the intermediate results are not needed elsewhere. This allows it to reduce data loading overhead and parallelize the workload efficiently.

    # Recommended: Method chaining for maximum JIT optimization
    fd.read_parquet("sample_data.parquet").pipe(lambda df: df[df["x"] == 1])["c"].sum()
  8. Avoid intermediate variables in notebooks for optimization

    main

    When working in a Jupyter notebook, avoid saving intermediate results in temporary variables.

    If you assign an intermediate result to a variable (e.g., df = fd.read_parquet(...)), the compiler assumes that the variable might be used in a later cell. Consequently, it keeps all intermediate data alive, which prevents the JIT compiler from performing full data-flow optimizations.

    Note: This limitation is specific to notebooks. In standard Python scripts, the compiler can inspect the entire file to determine if a variable is used later, allowing for optimization even with intermediate variables.

    # Inefficient in notebooks: Intermediate variables prevent optimization
    df = fd.read_parquet("sample_data.parquet")
    fdf = df[df["x"] == 1]
    fdf["c"].sum()