Skip to content

Commit

Permalink
fix: Fix error loading local dataframes into bigquery (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBergeron authored Nov 21, 2024
1 parent e7b83f1 commit 5b355ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bigframes/session/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ def read_pandas_load_job(
ordering_col = f"rowid_{suffix}"
suffix += 1

# Maybe should just convert to pyarrow or parquet?
pandas_dataframe_copy = pandas_dataframe.copy()
pandas_dataframe_copy.index.names = new_idx_ids
pandas_dataframe_copy.columns = pandas.Index(new_col_ids)
pandas_dataframe_copy[ordering_col] = np.arange(pandas_dataframe_copy.shape[0])
pandas_dataframe_copy = pandas_dataframe_copy.reset_index(drop=False)

job_config = bigquery.LoadJobConfig()
# Specify the datetime dtypes, which is auto-detected as timestamp types.
Expand Down
14 changes: 14 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def test_df_construct_pandas_load_job(scalars_dfs_maybe_ordered):
assert_dfs_equivalent(pd_result, bf_result)


def test_df_construct_structs(session):
pd_frame = pd.Series(
[
{"version": 1, "project": "pandas"},
{"version": 2, "project": "pandas"},
{"version": 1, "project": "numpy"},
]
).to_frame()
bf_series = session.read_pandas(pd_frame)
pd.testing.assert_frame_equal(
bf_series.to_pandas(), pd_frame, check_index_type=False, check_dtype=False
)


def test_df_construct_pandas_set_dtype(scalars_dfs):
columns = [
"int64_too",
Expand Down

0 comments on commit 5b355ef

Please sign in to comment.