Title: `DataFrame.to_gbq` with `if_exists="replace"` and `clustering_columns` can swap data between columns if order is different · Issue #2502 · googleapis/python-bigquery-dataframes · GitHub
Open Graph Title: `DataFrame.to_gbq` with `if_exists="replace"` and `clustering_columns` can swap data between columns if order is different · Issue #2502 · googleapis/python-bigquery-dataframes
X Title: `DataFrame.to_gbq` with `if_exists="replace"` and `clustering_columns` can swap data between columns if order is different · Issue #2502 · googleapis/python-bigquery-dataframes
Description: Environment details Python: 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ] bigframes==2.37.0 google-cloud-bigquery==3.40.1 pandas==3.0.1 pyarrow==23.0.1 Steps to reproduce Create a table with Dataframe.to_gbq with clustering_column...
Open Graph Description: Environment details Python: 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ] bigframes==2.37.0 google-cloud-bigquery==3.40.1 pandas==3.0.1 pyarrow==23.0.1 Steps to reproduce Create a table with...
X Description: Environment details Python: 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ] bigframes==2.37.0 google-cloud-bigquery==3.40.1 pandas==3.0.1 pyarrow==23.0.1 Steps to reproduce Create a table with...
Opengraph URL: https://github.com/googleapis/python-bigquery-dataframes/issues/2502
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`DataFrame.to_gbq` with `if_exists=\"replace\"` and `clustering_columns` can swap data between columns if order is different","articleBody":"#### Environment details\n\n```\nPython: 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ]\nbigframes==2.37.0\ngoogle-cloud-bigquery==3.40.1\npandas==3.0.1\npyarrow==23.0.1\n```\n\n#### Steps to reproduce\n\n 1. Create a table with `Dataframe.to_gbq` with `clustering_columns`\n 2. Reorder the clustering column and another column that has the same type \n 3. Write the updated dataframe to the same table with `if_exists=\"replace\"`\n 4. Inspect the table to see columns with different data than in dataframe\n\n#### Code example\n\n```python\nimport bigframes.pandas as bpd\nimport pandas as pd\n\nTABLE_ID = \"my_project.my_dataset.test_table\"\n\ndf = pd.DataFrame(\n {\"a\": [10, 1, 2], \"b\": [\"Justin\", \"Alex\", \"Jim\"], \"c\": [\"cat\", \"dog\", \"cat\"]}\n)\nbdf = bpd.DataFrame(df)\n\n# First time writing, all good\nbdf.to_gbq(TABLE_ID, clustering_columns=[\"b\"])\n\n# Reorder the clustered column b and column c\nbdf = bdf[[\"a\", \"c\", \"b\"]]\n\n# When replacing and writing, the b and c columns are swapped\nbdf.to_gbq(TABLE_ID, if_exists=\"replace\", clustering_columns=[\"b\"])\n```\n\nWhile the dataframe looks good, the updated table now has columns b/c data swapped:\n\n\u003cimg width=\"500\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/ba5a77dc-d404-4590-bafc-b56ac165dc2b\" /\u003e\n\n\u003cimg width=\"500\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/72119924-703c-490c-9a93-664f341a3c22\" /\u003e\n\nThis doesn't happen if `clustering_columns` is not used in my testing.","author":{"url":"https://github.com/jbandoro","@type":"Person","name":"jbandoro"},"datePublished":"2026-03-10T17:53:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2502/python-bigquery-dataframes/issues/2502"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:59d1b9b7-1aa2-55ac-3bdf-9ba8b17b5832 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E802:E1B7B:73AB8D:AA21B4:6A4E1490 |
| html-safe-nonce | 4459d406a05a28c196b5f7c9e8d5cc922bf9d31a40179c96c35cd504715dca1a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODAyOkUxQjdCOjczQUI4RDpBQTIxQjQ6NkE0RTE0OTAiLCJ2aXNpdG9yX2lkIjoiNTMwNDE1MTg3MjA4NDI1MTc5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd81879e84e35e3eec233f3bce4a0ba39ec5fb28e5572a1759212ff94b970483 |
| hovercard-subject-tag | issue:4053317601 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-bigquery-dataframes/2502/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3856ec162d288a3443cca37e4c7327510bb8274cc7c75c838bbbcbf8717bff34/googleapis/python-bigquery-dataframes/issues/2502 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3856ec162d288a3443cca37e4c7327510bb8274cc7c75c838bbbcbf8717bff34/googleapis/python-bigquery-dataframes/issues/2502 |
| og:image:alt | Environment details Python: 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ] bigframes==2.37.0 google-cloud-bigquery==3.40.1 pandas==3.0.1 pyarrow==23.0.1 Steps to reproduce Create a table with... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jbandoro |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-bigquery-dataframes git https://github.com/googleapis/python-bigquery-dataframes.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 667598363 |
| octolytics-dimension-repository_nwo | googleapis/python-bigquery-dataframes |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 667598363 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-bigquery-dataframes |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ea9187571e3edc5f2780f750631138669441ca50 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width