Skip to content

Commit 3b79421

Browse files
committed
fix: resolve MM dataframe visualization size mismatch
1 parent 95c4eba commit 3b79421

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

bigframes/core/blocks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,9 +1822,9 @@ def melt(
18221822
Arguments correspond to pandas.melt arguments.
18231823
"""
18241824
# TODO: Implement col_level and ignore_index
1825-
value_labels: pd.Index = pd.Index(
1826-
[self.col_id_to_label[col_id] for col_id in value_vars]
1827-
)
1825+
value_labels: pd.Index = self.column_labels[
1826+
[self.value_columns.index(col_id) for col_id in value_vars]
1827+
]
18281828
id_labels = [self.col_id_to_label[col_id] for col_id in id_vars]
18291829

18301830
unpivot_expr, (var_col_ids, unpivot_out, passthrough_cols) = unpivot(

tests/system/small/test_dataframe.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5876,6 +5876,31 @@ def test_to_gbq_table_labels(scalars_df_index):
58765876
assert table.labels["test"] == "labels"
58775877

58785878

5879+
def test_to_gbq_obj_ref_persists(session):
5880+
# Test that saving and loading an Object Reference retains its dtype
5881+
bdf = session.from_glob_path(
5882+
"gs://cloud-samples-data/vision/ocr/*.jpg", name="uris"
5883+
).head(1)
5884+
5885+
destination_table = "bigframes-dev.bigframes_tests_sys.test_obj_ref_persistence"
5886+
bdf.to_gbq(destination_table, if_exists="replace")
5887+
5888+
loaded_df = session.read_gbq(destination_table)
5889+
assert loaded_df["uris"].dtype == dtypes.OBJ_REF_DTYPE
5890+
5891+
5892+
def test_dataframe_melt_multiindex(session):
5893+
# Tests that `melt` operations via count do not cause MultiIndex drops in Arrow
5894+
df = pd.DataFrame({"A": [1], "B": ["string"], "C": [3]})
5895+
df.columns = pd.MultiIndex.from_tuples(
5896+
[("Group1", "A"), ("Group2", "B"), ("Group1", "C")]
5897+
)
5898+
bdf = session.read_pandas(df)
5899+
5900+
count_df = bdf.count().to_pandas()
5901+
assert count_df.shape[0] == 3
5902+
5903+
58795904
@pytest.mark.parametrize(
58805905
("col_names", "ignore_index"),
58815906
[

0 commit comments

Comments
 (0)