diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index 5d17ae20defb..fc6f892a25ca 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -7285,7 +7285,8 @@ def join( other DataFrame to join with. on - Name(s) of the join columns in both DataFrames. + Name(s) of the join columns in both DataFrames. If set, `left_on` and + `right_on` should be None. This should not be specified if `how="cross"`. how : {'inner', 'left', 'right', 'full', 'semi', 'anti', 'cross'} Join strategy. @@ -7447,6 +7448,24 @@ def join( │ 3 ┆ 8.0 ┆ c │ └─────┴─────┴─────┘ + >>> df.join(other_df, how="cross") + shape: (9, 5) + ┌─────┬─────┬─────┬───────┬───────────┐ + │ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │ + │ --- ┆ --- ┆ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str ┆ str ┆ str │ + ╞═════╪═════╪═════╪═══════╪═══════════╡ + │ 1 ┆ 6.0 ┆ a ┆ x ┆ a │ + │ 1 ┆ 6.0 ┆ a ┆ y ┆ b │ + │ 1 ┆ 6.0 ┆ a ┆ z ┆ d │ + │ 2 ┆ 7.0 ┆ b ┆ x ┆ a │ + │ 2 ┆ 7.0 ┆ b ┆ y ┆ b │ + │ 2 ┆ 7.0 ┆ b ┆ z ┆ d │ + │ 3 ┆ 8.0 ┆ c ┆ x ┆ a │ + │ 3 ┆ 8.0 ┆ c ┆ y ┆ b │ + │ 3 ┆ 8.0 ┆ c ┆ z ┆ d │ + └─────┴─────┴─────┴───────┴───────────┘ + Notes ----- For joining on columns with categorical data, see :class:`polars.StringCache`. diff --git a/py-polars/polars/lazyframe/frame.py b/py-polars/polars/lazyframe/frame.py index e84318a3021b..bf386132bb47 100644 --- a/py-polars/polars/lazyframe/frame.py +++ b/py-polars/polars/lazyframe/frame.py @@ -4643,8 +4643,8 @@ def join( other Lazy DataFrame to join with. on - Join column of both DataFrames. If set, `left_on` and `right_on` should be - None. + Name(s) of the join columns in both DataFrames. If set, `left_on` and + `right_on` should be None. This should not be specified if `how="cross"`. how : {'inner', 'left', 'right', 'full', 'semi', 'anti', 'cross'} Join strategy. @@ -4793,6 +4793,24 @@ def join( ╞═════╪═════╪═════╡ │ 3 ┆ 8.0 ┆ c │ └─────┴─────┴─────┘ + + >>> lf.join(other_lf, how="cross").collect() + shape: (9, 5) + ┌─────┬─────┬─────┬───────┬───────────┐ + │ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │ + │ --- ┆ --- ┆ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str ┆ str ┆ str │ + ╞═════╪═════╪═════╪═══════╪═══════════╡ + │ 1 ┆ 6.0 ┆ a ┆ x ┆ a │ + │ 1 ┆ 6.0 ┆ a ┆ y ┆ b │ + │ 1 ┆ 6.0 ┆ a ┆ z ┆ d │ + │ 2 ┆ 7.0 ┆ b ┆ x ┆ a │ + │ 2 ┆ 7.0 ┆ b ┆ y ┆ b │ + │ 2 ┆ 7.0 ┆ b ┆ z ┆ d │ + │ 3 ┆ 8.0 ┆ c ┆ x ┆ a │ + │ 3 ┆ 8.0 ┆ c ┆ y ┆ b │ + │ 3 ┆ 8.0 ┆ c ┆ z ┆ d │ + └─────┴─────┴─────┴───────┴───────────┘ """ if not isinstance(other, LazyFrame): msg = f"expected `other` join table to be a LazyFrame, not a {type(other).__name__!r}"