Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(python): Add more information for cross joins #20753

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading