Skip to content

Commit

Permalink
docs(python): Add more information for cross joins (#20753)
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher authored Jan 16, 2025
1 parent 54fc488 commit 6ce00e1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
21 changes: 20 additions & 1 deletion py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down
22 changes: 20 additions & 2 deletions py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 6ce00e1

Please sign in to comment.