-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(bigframes): Gcs bucket read will bind to gcs region if region unset #16855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -127,3 +127,43 @@ def test_read_gbq_colab_calls_set_location( | |||||
| assert kwargs["pyformat_args"] == sample_pyformat_args | ||||||
| assert not kwargs["dry_run"] | ||||||
| assert isinstance(result, bigframes.dataframe.DataFrame) | ||||||
|
|
||||||
|
|
||||||
| @mock.patch("bigframes.pandas.io.api._get_storage_client") | ||||||
| @mock.patch("bigframes.core.global_session.with_default_session") | ||||||
| def test_read_csv_gcs_sets_location(mock_with_default_session, mock_get_storage_client): | ||||||
| mock_storage_client = mock.Mock() | ||||||
| mock_bucket = mock.Mock() | ||||||
| mock_bucket.location = "us-east1" | ||||||
| mock_storage_client.get_bucket.return_value = mock_bucket | ||||||
| mock_get_storage_client.return_value = mock_storage_client | ||||||
|
|
||||||
| import bigframes._config as config | ||||||
| config.options.bigquery.location = None | ||||||
| config.options.bigquery._session_started = False | ||||||
| config.options.bigquery.use_regional_endpoints = None | ||||||
|
|
||||||
| bf_io_api.read_csv("gs://test-bucket/file.csv") | ||||||
|
|
||||||
| assert config.options.bigquery.location == "us-east1" | ||||||
|
|
||||||
|
|
||||||
| @mock.patch("bigframes.pandas.io.api._get_storage_client") | ||||||
| @mock.patch("bigframes.core.global_session.with_default_session") | ||||||
| def test_read_csv_gcs_doesnt_overwrite_set_location(mock_with_default_session, mock_get_storage_client): | ||||||
| mock_storage_client = mock.Mock() | ||||||
| mock_bucket = mock.Mock() | ||||||
| mock_bucket.location = "us-east1" | ||||||
| mock_storage_client.get_bucket.return_value = mock_bucket | ||||||
| mock_get_storage_client.return_value = mock_storage_client | ||||||
|
|
||||||
| import bigframes._config as config | ||||||
| config.options.bigquery.location = "eu" | ||||||
| config.options.bigquery._session_started = False | ||||||
| config.options.bigquery.use_regional_endpoints = None | ||||||
|
|
||||||
| bf_io_api.read_csv("gs://test-bucket/file.csv") | ||||||
|
|
||||||
| assert config.options.bigquery.location == "EU" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion expects "EU", but the location was set to "eu" at line 161. Since _set_default_session_location_if_possible_gcs returns early when a location is already set, the value will remain "eu", causing this test to fail. Based on the previous test case (line 148), locations appear to be case-sensitive in these assertions.
Suggested change
|
||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
_default_location_lockis used but not defined at the module level, and thethreadingmodule is not imported in this file. This will result in aNameErrorat runtime when_set_default_session_location_if_possible_gcsis called. Please define the lock at the module level (e.g.,_default_location_lock = threading.Lock()) and ensurethreadingis imported.