Skip to content

Commit ee37a0a

Browse files
feat: DataFrame.join supports Series other (#1303)
1 parent 774e56b commit ee37a0a

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

bigframes/dataframe.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,8 +3033,15 @@ def merge(
30333033
return DataFrame(block)
30343034

30353035
def join(
3036-
self, other: DataFrame, *, on: Optional[str] = None, how: str = "left"
3036+
self,
3037+
other: Union[DataFrame, bigframes.series.Series],
3038+
*,
3039+
on: Optional[str] = None,
3040+
how: str = "left",
30373041
) -> DataFrame:
3042+
if isinstance(other, bigframes.series.Series):
3043+
other = other.to_frame()
3044+
30383045
left, right = self, other
30393046

30403047
if not left.columns.intersection(right.columns).empty:

tests/system/small/test_dataframe.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,27 @@ def test_join_param_on(scalars_dfs, how):
25542554
assert_pandas_df_equal(bf_result, pd_result, ignore_order=True)
25552555

25562556

2557+
@all_joins
2558+
def test_df_join_series(scalars_dfs, how):
2559+
bf_df, pd_df = scalars_dfs
2560+
2561+
bf_df_a = bf_df[["string_col", "int64_col", "rowindex_2"]]
2562+
bf_df_a = bf_df_a.assign(rowindex_2=bf_df_a["rowindex_2"] + 2)
2563+
bf_series_b = bf_df["float64_col"]
2564+
2565+
if how == "cross":
2566+
with pytest.raises(ValueError):
2567+
bf_df_a.join(bf_series_b, on="rowindex_2", how=how)
2568+
else:
2569+
bf_result = bf_df_a.join(bf_series_b, on="rowindex_2", how=how).to_pandas()
2570+
2571+
pd_df_a = pd_df[["string_col", "int64_col", "rowindex_2"]]
2572+
pd_df_a = pd_df_a.assign(rowindex_2=pd_df_a["rowindex_2"] + 2)
2573+
pd_series_b = pd_df["float64_col"]
2574+
pd_result = pd_df_a.join(pd_series_b, on="rowindex_2", how=how)
2575+
assert_pandas_df_equal(bf_result, pd_result, ignore_order=True)
2576+
2577+
25572578
@pytest.mark.parametrize(
25582579
("by", "ascending", "na_position"),
25592580
[

third_party/bigframes_vendored/pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4384,7 +4384,7 @@ def join(self, other, *, on: Optional[str] = None, how: str) -> DataFrame:
43844384
43854385
Args:
43864386
other:
4387-
DataFrame with an Index similar to the Index of this one.
4387+
DataFrame or Series with an Index similar to the Index of this one.
43884388
on:
43894389
Column in the caller to join on the index in other, otherwise
43904390
joins index-on-index. Like an Excel VLOOKUP operation.

0 commit comments

Comments
 (0)