{"record":{"id":"f8032833b189842d","repo":"pola-rs/polars","slug":"right-join-column-name-r-not-found","errorCode":null,"errorMessage":"right join column {name!r} not found","messagePattern":"right join column (.+?) not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/frame.py","lineNumber":9073,"sourceCode":"        else:\n            # move on into left/right_on to simplify logic\n            left_on = right_on = on\n\n        if isinstance(left_on, str):\n            left_on = [left_on]\n        if isinstance(right_on, str):\n            right_on = [right_on]\n\n        left_schema = self.collect_schema()\n        for name in left_on:\n            if name not in left_schema:\n                msg = f\"left join column {name!r} not found\"\n                raise ValueError(msg)\n        right_schema = other.collect_schema()\n        for name in right_on:\n            if name not in right_schema:\n                msg = f\"right join column {name!r} not found\"\n                raise ValueError(msg)\n\n        # no need to join if *only* join columns are in other (inner/left update only)\n        if how != \"full\" and len(right_schema) == len(right_on):\n            if row_index_name is not None:\n                return self.drop(row_index_name)\n            return self\n\n        # only use non-idx right columns present in left frame\n        right_other = set(right_schema).intersection(left_schema) - set(right_on)\n\n        # When include_nulls is True, we need to distinguish records after the join that\n        # were originally null in the right frame, as opposed to records that were null\n        # because the key was missing from the right frame.\n        # Add a validity column to track whether row was matched or not.\n        if include_nulls:\n            validity = (\"__POLARS_VALIDITY\",)\n            other = other.with_columns(F.lit(True).alias(validity[0]))\n        else:","sourceCodeStart":9055,"sourceCodeEnd":9091,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/frame.py#L9055-L9091","documentation":"Pre-flight join-key check in LazyFrame.join (left/right join paths): right_on columns are validated against the right frame's collected schema; a key name that is not a column of the other frame raises before execution, catching typos early.","triggerScenarios":"Calling `lf.join(other, right_on=\"rid\", ...)` where `other` lacks a column 'rid' — the loop over right_schema raises on the first missing name.","commonSituations":"Right frame loaded from a different source with changed column names; forgot to select/rename the key column on `other`; swapped arguments.","solutions":["Verify with `other.collect_schema().names()` and correct the right_on name.","Rename or add the key column on `other` before joining.","Confirm the right frame is the intended one."],"exampleFix":"// before\nlf.join(other, left_on=\"lid\", right_on=\"rid\")  # other lacks 'rid'\n// after\nother = other.rename({\"r_id\": \"rid\"})\nlf.join(other, left_on=\"lid\", right_on=\"rid\")","handlingStrategy":"validation","validationCode":"right_schema = other.collect_schema()\nmissing = [c for c in right_on if c not in right_schema]\nif missing:\n    raise ValueError(f\"right frame missing join columns: {missing}\")","typeGuard":null,"tryCatchPattern":"try:\n    out = lf.join(other, left_on=left_on, right_on=right_on, how=how)\nexcept ValueError as e:\n    if \"right join column\" in str(e):\n        raise KeyError(f\"right frame columns: {other.collect_schema().names()}\") from e\n    raise","preventionTips":["Validate right frame schema with collect_schema() before joining.","Rename key columns on `other` at load time to match the left frame.","Confirm argument order — swapped left/right frames cause this error."],"tags":["python","polars","join","schema","column-not-found"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}