Skip to content

Commit a217c20

Browse files
committed
add testcase
1 parent df0b463 commit a217c20

File tree

4 files changed

+100
-41
lines changed

4 files changed

+100
-41
lines changed

tests/system/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,27 @@ def scalars_df_2_index(
601601
return session.read_gbq(scalars_table_id_2, index_col="rowindex")
602602

603603

604+
@pytest.fixture(scope="session")
605+
def scalars_df_null_index_partial_ordering(
606+
scalars_table_id: str, unordered_session: bigframes.Session
607+
) -> bigframes.dataframe.DataFrame:
608+
"""DataFrame pointing at test data with null index in partial ordering mode."""
609+
return unordered_session.read_gbq(
610+
scalars_table_id, index_col=bigframes.enums.DefaultIndexKind.NULL
611+
).sort_values("rowindex")
612+
613+
614+
@pytest.fixture(scope="session")
615+
def scalars_series_null_index_partial_ordering(
616+
scalars_table_id: str, unordered_session: bigframes.Session
617+
) -> bigframes.series.Series:
618+
"""Series pointing at test data with null index in partial ordering mode."""
619+
df = unordered_session.read_gbq(
620+
scalars_table_id, index_col=bigframes.enums.DefaultIndexKind.NULL
621+
).sort_values("rowindex")
622+
return df["int64_col"]
623+
624+
604625
@pytest.fixture(scope="session")
605626
def scalars_pandas_df_default_index() -> pd.DataFrame:
606627
"""pd.DataFrame pointing at test data."""
@@ -1529,3 +1550,12 @@ def audio_mm_df(
15291550
return session.from_glob_path(
15301551
audio_gcs_path, name="audio", connection=bq_connection
15311552
)
1553+
1554+
1555+
@pytest.fixture(scope="session")
1556+
def audio_mm_df_partial_ordering(
1557+
audio_gcs_path, unordered_session: bigframes.Session, bq_connection: str
1558+
) -> bpd.DataFrame:
1559+
return unordered_session.from_glob_path(
1560+
audio_gcs_path, name="audio", connection=bq_connection
1561+
)

tests/system/large/blob/test_function.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,27 @@ def test_blob_transcribe(
454454
assert (
455455
keyword.lower() in actual_text.lower()
456456
), f"Item (verbose={verbose}): Expected keyword '{keyword}' not found in transcribed text. "
457+
458+
459+
@pytest.mark.parametrize(
460+
"model_name",
461+
[
462+
"gemini-2.0-flash-001",
463+
"gemini-2.0-flash-lite-001",
464+
],
465+
)
466+
def test_audio_transcribe_partial_ordering_integration(
467+
audio_mm_df_partial_ordering: bpd.DataFrame,
468+
model_name: str,
469+
):
470+
"""Integration test for audio_transcribe with partial ordering mode."""
471+
df = audio_mm_df_partial_ordering.copy()
472+
473+
bpd.options.bigquery.ordering_mode = "partial"
474+
475+
df["transcribed_text"] = df["audio"].blob.audio_transcribe(model_name=model_name)
476+
result = df.to_pandas(ordered=False)
477+
478+
assert "transcribed_text" in result.columns
479+
assert len(result) > 0
480+
assert result["transcribed_text"].iloc[0] is not None

tests/system/small/test_dataframe.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,26 +2949,41 @@ 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,
2952+
def test_assign_series_with_null_index_should_add_column_correctly(
2953+
scalars_df_null_index_partial_ordering: bigframes.dataframe.DataFrame,
2954+
scalars_series_null_index_partial_ordering: bigframes.series.Series,
29552955
):
29562956
"""Test that DataFrame column assignment works with null indices in partial ordering mode."""
2957+
df = scalars_df_null_index_partial_ordering[["int64_col", "string_col"]].head(3)
2958+
series_to_assign = scalars_series_null_index_partial_ordering.head(3)
29572959

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)
2960+
expected_series = pd.Series(
2961+
[
2962+
-987654321,
2963+
-987654321,
2964+
-987654321,
2965+
314159,
2966+
314159,
2967+
314159,
2968+
123456789,
2969+
123456789,
2970+
123456789,
2971+
],
2972+
dtype="Int64",
2973+
)
29622974

2975+
# Assign the Series as a new column in the DataFrame
29632976
df["new_col"] = series_to_assign
2964-
result_df = df.to_pandas(ordered=False)
29652977

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
2978+
# Materialize the full DataFrame to a pandas object to get the computed result.
2979+
result_df = df[["int64_col", "new_col"]].to_pandas()
2980+
result_series = result_df["new_col"]
29692981

2970-
# Verify the assigned values are exactly what we expect
2971-
assert result_df["new_col"].tolist() == [10, 20, 30]
2982+
pd.testing.assert_series_equal(
2983+
result_series.sort_values().reset_index(drop=True),
2984+
expected_series,
2985+
check_names=False,
2986+
)
29722987

29732988

29742989
@pytest.mark.parametrize(

tests/system/small/test_null_index.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515

1616
import pandas as pd
17+
import pandas.testing
1718
import pytest
1819

1920
import bigframes.core
2021
import bigframes.core.blocks as blocks
21-
import bigframes.core.local_data as local_data
2222
import bigframes.exceptions
2323
import bigframes.pandas as bpd
2424

@@ -408,42 +408,32 @@ def test_null_index_transpose(scalars_df_null_index):
408408
pytest.param("unordered_session"),
409409
],
410410
)
411-
def test_block_join_identity_null_index(request, session_fixture):
411+
def test_identity_join_with_null_index_should_return_cartesian_product(
412+
request, session_fixture
413+
):
412414
"""Test the Block.join method with block_identity_join=True and null indices."""
413-
414415
session = request.getfixturevalue(session_fixture)
415-
416416
left_data = pd.DataFrame({"a": [1, 2, 3]})
417417
right_data = pd.DataFrame({"b": [10, 20, 30]})
418418

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)
419+
left_block = blocks.Block.from_local(left_data, session=session)
420+
right_block = blocks.Block.from_local(right_data, session=session)
424421

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"],
422+
expected_df = pd.DataFrame(
423+
{
424+
"a": [1, 2, 3],
425+
"b": [10, 20, 30],
426+
}
435427
)
436428

437-
# Test the join with block_identity_join=True
429+
# Perform the identity join on the two blocks
438430
result_block, (left_mapping, right_mapping) = left_block.join(
439431
right_block, how="left", block_identity_join=True
440432
)
441433

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
434+
result_df, _ = result_block.to_pandas()
435+
pandas.testing.assert_frame_equal(
436+
result_df.sort_values(by=["a", "b"]).reset_index(drop=True),
437+
expected_df,
438+
check_dtype=False,
439+
)

0 commit comments

Comments
 (0)