Skip to content

Commit df0b463

Browse files
committed
handle corner case of null ptr
1 parent 566b5b0 commit df0b463

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

bigframes/core/blocks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,11 @@ def join(
24882488
)
24892489
if result is not None:
24902490
return result
2491+
2492+
# For block identify joins with null indices, perform cross join
2493+
if block_identity_join and how == "left":
2494+
return join_with_single_row(self, other)
2495+
24912496
raise bigframes.exceptions.NullIndexError(
24922497
"Cannot implicitly align objects. Set an explicit index using set_index."
24932498
)

bigframes/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,7 @@ def _assign_series_join_on_index(
22892289
self, label: str, series: bigframes.series.Series
22902290
) -> DataFrame:
22912291
block, (get_column_left, get_column_right) = self._block.join(
2292-
series._block, how="left"
2292+
series._block, how="left", block_identity_join=True
22932293
)
22942294

22952295
column_ids = [

tests/system/small/test_dataframe.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,28 @@ def test_df_join_series(scalars_dfs, how):
29492949
assert_pandas_df_equal(bf_result, pd_result, ignore_order=True)
29502950

29512951

2952+
def test_dataframe_assign_series_null_index_partial_ordering(
2953+
scalars_df_null_index: bigframes.dataframe.DataFrame,
2954+
unordered_session: bigframes.Session,
2955+
):
2956+
"""Test that DataFrame column assignment works with null indices in partial ordering mode."""
2957+
2958+
# Use existing null index DataFrame but create Series in unordered session
2959+
df = scalars_df_null_index[["int64_col", "string_col"]].head(3)
2960+
# Create Series with explicit values in unordered session
2961+
series_to_assign = bpd.Series([10, 20, 30], session=unordered_session)
2962+
2963+
df["new_col"] = series_to_assign
2964+
result_df = df.to_pandas(ordered=False)
2965+
2966+
# Verify the column was added and has the correct length
2967+
assert "new_col" in result_df.columns
2968+
assert len(result_df) == 3
2969+
2970+
# Verify the assigned values are exactly what we expect
2971+
assert result_df["new_col"].tolist() == [10, 20, 30]
2972+
2973+
29522974
@pytest.mark.parametrize(
29532975
("by", "ascending", "na_position"),
29542976
[

tests/system/small/test_null_index.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import pandas as pd
1717
import pytest
1818

19+
import bigframes.core
20+
import bigframes.core.blocks as blocks
21+
import bigframes.core.local_data as local_data
1922
import bigframes.exceptions
2023
import bigframes.pandas as bpd
2124

@@ -398,5 +401,49 @@ def test_null_index_transpose(scalars_df_null_index):
398401
_ = scalars_df_null_index.T
399402

400403

401-
def test_null_index_contains(scalars_df_null_index):
402-
assert 3 not in scalars_df_null_index
404+
@pytest.mark.parametrize(
405+
("session_fixture",),
406+
[
407+
pytest.param("session"),
408+
pytest.param("unordered_session"),
409+
],
410+
)
411+
def test_block_join_identity_null_index(request, session_fixture):
412+
"""Test the Block.join method with block_identity_join=True and null indices."""
413+
414+
session = request.getfixturevalue(session_fixture)
415+
416+
left_data = pd.DataFrame({"a": [1, 2, 3]})
417+
right_data = pd.DataFrame({"b": [10, 20, 30]})
418+
419+
left_managed = local_data.ManagedArrowTable.from_pandas(left_data)
420+
right_managed = local_data.ManagedArrowTable.from_pandas(right_data)
421+
422+
left_array = bigframes.core.ArrayValue.from_managed(left_managed, session=session)
423+
right_array = bigframes.core.ArrayValue.from_managed(right_managed, session=session)
424+
425+
# Create blocks with empty index_columns to get null indices
426+
left_block = blocks.Block(
427+
left_array,
428+
index_columns=[],
429+
column_labels=["a"],
430+
)
431+
right_block = blocks.Block(
432+
right_array,
433+
index_columns=[],
434+
column_labels=["b"],
435+
)
436+
437+
# Test the join with block_identity_join=True
438+
result_block, (left_mapping, right_mapping) = left_block.join(
439+
right_block, how="left", block_identity_join=True
440+
)
441+
442+
# Verify both have null indices
443+
assert left_block.index.nlevels == 0
444+
assert right_block.index.nlevels == 0
445+
446+
# Verify the join succeeded
447+
assert result_block is not None
448+
assert len(left_mapping) > 0
449+
assert len(right_mapping) > 0

0 commit comments

Comments
 (0)