Skip to content

Commit 6ce00e1

Browse files
docs(python): Add more information for cross joins (#20753)
1 parent 54fc488 commit 6ce00e1

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

py-polars/polars/dataframe/frame.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -7285,7 +7285,8 @@ def join(
72857285
other
72867286
DataFrame to join with.
72877287
on
7288-
Name(s) of the join columns in both DataFrames.
7288+
Name(s) of the join columns in both DataFrames. If set, `left_on` and
7289+
`right_on` should be None. This should not be specified if `how="cross"`.
72897290
how : {'inner', 'left', 'right', 'full', 'semi', 'anti', 'cross'}
72907291
Join strategy.
72917292
@@ -7447,6 +7448,24 @@ def join(
74477448
│ 3 ┆ 8.0 ┆ c │
74487449
└─────┴─────┴─────┘
74497450
7451+
>>> df.join(other_df, how="cross")
7452+
shape: (9, 5)
7453+
┌─────┬─────┬─────┬───────┬───────────┐
7454+
│ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │
7455+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
7456+
│ i64 ┆ f64 ┆ str ┆ str ┆ str │
7457+
╞═════╪═════╪═════╪═══════╪═══════════╡
7458+
│ 1 ┆ 6.0 ┆ a ┆ x ┆ a │
7459+
│ 1 ┆ 6.0 ┆ a ┆ y ┆ b │
7460+
│ 1 ┆ 6.0 ┆ a ┆ z ┆ d │
7461+
│ 2 ┆ 7.0 ┆ b ┆ x ┆ a │
7462+
│ 2 ┆ 7.0 ┆ b ┆ y ┆ b │
7463+
│ 2 ┆ 7.0 ┆ b ┆ z ┆ d │
7464+
│ 3 ┆ 8.0 ┆ c ┆ x ┆ a │
7465+
│ 3 ┆ 8.0 ┆ c ┆ y ┆ b │
7466+
│ 3 ┆ 8.0 ┆ c ┆ z ┆ d │
7467+
└─────┴─────┴─────┴───────┴───────────┘
7468+
74507469
Notes
74517470
-----
74527471
For joining on columns with categorical data, see :class:`polars.StringCache`.

py-polars/polars/lazyframe/frame.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -4643,8 +4643,8 @@ def join(
46434643
other
46444644
Lazy DataFrame to join with.
46454645
on
4646-
Join column of both DataFrames. If set, `left_on` and `right_on` should be
4647-
None.
4646+
Name(s) of the join columns in both DataFrames. If set, `left_on` and
4647+
`right_on` should be None. This should not be specified if `how="cross"`.
46484648
how : {'inner', 'left', 'right', 'full', 'semi', 'anti', 'cross'}
46494649
Join strategy.
46504650
@@ -4793,6 +4793,24 @@ def join(
47934793
╞═════╪═════╪═════╡
47944794
│ 3 ┆ 8.0 ┆ c │
47954795
└─────┴─────┴─────┘
4796+
4797+
>>> lf.join(other_lf, how="cross").collect()
4798+
shape: (9, 5)
4799+
┌─────┬─────┬─────┬───────┬───────────┐
4800+
│ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │
4801+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
4802+
│ i64 ┆ f64 ┆ str ┆ str ┆ str │
4803+
╞═════╪═════╪═════╪═══════╪═══════════╡
4804+
│ 1 ┆ 6.0 ┆ a ┆ x ┆ a │
4805+
│ 1 ┆ 6.0 ┆ a ┆ y ┆ b │
4806+
│ 1 ┆ 6.0 ┆ a ┆ z ┆ d │
4807+
│ 2 ┆ 7.0 ┆ b ┆ x ┆ a │
4808+
│ 2 ┆ 7.0 ┆ b ┆ y ┆ b │
4809+
│ 2 ┆ 7.0 ┆ b ┆ z ┆ d │
4810+
│ 3 ┆ 8.0 ┆ c ┆ x ┆ a │
4811+
│ 3 ┆ 8.0 ┆ c ┆ y ┆ b │
4812+
│ 3 ┆ 8.0 ┆ c ┆ z ┆ d │
4813+
└─────┴─────┴─────┴───────┴───────────┘
47964814
"""
47974815
if not isinstance(other, LazyFrame):
47984816
msg = f"expected `other` join table to be a LazyFrame, not a {type(other).__name__!r}"

0 commit comments

Comments
 (0)