pola-rs/polars · error

not yet implemented

Error message

not yet implemented

What it means

StructArray implements array-vs-array total equality (the bitmap loop shown above the stub), but the broadcast variant tot_eq_kernel_broadcast - comparing every struct element against one scalar struct - is a todo!() stub. So a Struct column equals-comparison against a single literal panics with 'not yet implemented' even though column-to-column == works.

Source

Thrown at crates/polars-compute/src/comparisons/struct_.rs:102

                    is_equal = false;
                    break;
                }

                let result = array_tot_eq_missing_kernel(lv[j].as_ref(), rv[j].as_ref());
                if result.unset_bits() != 0 {
                    is_equal = false;
                    break;
                }
            }

            bitmap.push(!is_equal);
        }

        bitmap.freeze()
    }

    fn tot_eq_kernel_broadcast(&self, _other: &Self::Scalar) -> Bitmap {
        todo!()
    }

    fn tot_ne_kernel_broadcast(&self, _other: &Self::Scalar) -> Bitmap {
        todo!()
    }
}

View on GitHub (pinned to 9b5d73fd00)

Solutions

  1. Compare field-by-field: (pl.col("s").struct.field("a") == 1) & (pl.col("s").struct.field("b") == "x")
  2. Turn the literal into a same-length struct expression and compare columns, avoiding scalar broadcast: pl.struct([pl.lit(1).alias("a")]) expanded to the frame height
  3. Implement tot_eq_kernel_broadcast for StructArray upstream by reusing the per-field array-vs-array path with broadcast scalars

Example fix

# before
df.filter(pl.col("s") == {"a": 1, "b": "x"})  # todo!: broadcast not implemented
# after
df.filter(
    (pl.col("s").struct.field("a") == 1)
    & (pl.col("s").struct.field("b") == "x")
)
Defensive patterns

Strategy: fallback

Validate before calling

# detect struct-vs-literal comparisons before running the query
if isinstance(literal, dict) and df.schema[col_name] == pl.Struct:
    expr = pl.all_horizontal([
        pl.col(col_name).struct.field(k) == v for k, v in literal.items()
    ])  # instead of pl.col(col_name) == literal

Type guard

def is_struct_column(dtype) -> bool:
    return isinstance(dtype, pl.Struct) or getattr(dtype, "base_type", None) == pl.Struct

Try / catch

try:
    df.filter(pl.col("s") == literal)
except pl.exceptions.PanicException:
    expr = pl.all_horizontal([pl.col("s").struct.field(k) == v for k, v in literal.items()])
    df = df.filter(expr)

Prevention

When it happens

Trigger: pl.col("s") == {"a": 1} against a struct column; df.filter(pl.col("struct_col") == pl.struct([pl.lit(1).alias("a")])); Series == scalar struct; any expression where a length-1 struct literal is broadcast against an n-row Struct column.

Common situations: Query-builder code that stores coordinates/metadata as struct columns and filters 'rows equal to this constant struct' (matching a specific (x, y) pair or payload snapshot); pipelines that compare two struct columns fine and later switch one side to a literal, then panic.

Related errors


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/a11e98afa0203edf. Report an issue: GitHub.