From 7abf188aca6b32b0209cd32c11136b32535f06df Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 19:47:00 -0800 Subject: [PATCH 01/15] feat: add 'columns' as an alias for 'col_order' --- docs/reading.rst | 3 ++- pandas_gbq/gbq.py | 6 ++++++ tests/system/test_gbq.py | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/reading.rst b/docs/reading.rst index c5e814bf..a1ba0a5e 100644 --- a/docs/reading.rst +++ b/docs/reading.rst @@ -28,7 +28,8 @@ destination DataFrame as well as a preferred column order as follows: 'SELECT * FROM `test_dataset.test_table`', project_id=projectid, index_col='index_column_name', - col_order=['col1', 'col2', 'col3']) + col_order=['col1', 'col2', 'col3'], + columns=['col1', 'col2']) Querying with legacy SQL syntax ------------------------------- diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index 26a566d9..9f091d0b 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -733,6 +733,7 @@ def read_gbq( project_id=None, index_col=None, col_order=None, + columns=None, reauth=False, auth_local_webserver=True, dialect=None, @@ -774,6 +775,8 @@ def read_gbq( col_order : list(str), optional List of BigQuery column names in the desired order for results DataFrame. + columns : list(str), optional + List of BigQuery column names to return, alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. @@ -964,6 +967,9 @@ def read_gbq( 'Index column "{0}" does not exist in DataFrame.'.format(index_col) ) + # Creating an alias for col_order, which is columns + col_order = col_order or columns + # Change the order of columns in the DataFrame based on provided list if col_order is not None: if sorted(col_order) == sorted(final_df.columns): diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 9aac2357..183bcb8a 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -600,6 +600,26 @@ def test_tokyo(self, tokyo_dataset, tokyo_table, project_id): ) assert df["max_year"][0] >= 2000 + def test_columns_and_col_order(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1"] + col_order = ["string_3", "string_1", "string_2"] + result_frame = gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + col_order=col_order, + credentials=self.credentials, + dialect="standard", + ) + correct_frame = DataFrame( + {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} + )[col_order] + tm.assert_frame_equal(result_frame, correct_frame) + + # Verify that col_order is prioritized over columns + assert sorted(col_order) == sorted(result_frame.columns) + class TestToGBQIntegration(object): @pytest.fixture(autouse=True, scope="function") From 5b7b11243ee582e79909519f3991832c33f09abe Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 20:16:00 -0800 Subject: [PATCH 02/15] Added test to test alias correctness --- tests/system/test_gbq.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 183bcb8a..3fc985eb 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -619,6 +619,29 @@ def test_columns_and_col_order(self, project_id): # Verify that col_order is prioritized over columns assert sorted(col_order) == sorted(result_frame.columns) + + def test_col_order_as_alias(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1", "string_3"] + # Not explicitly specifying col_order + + result_frame = gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + credentials=self.credentials, + dialect="standard", + ) + + correct_frame = DataFrame( + {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} + )[columns] + + # Verify that the result_frame matches the expected DataFrame + tm.assert_frame_equal(result_frame, correct_frame) + + # Ensure that the order of columns in the result_frame matches the specified order + assert sorted(columns) == sorted(result_frame.columns) class TestToGBQIntegration(object): From 4bdc620534d9590317b0a8f9286dfec53eda661a Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 20:16:44 -0800 Subject: [PATCH 03/15] reformatted with black --- tests/system/test_gbq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 3fc985eb..076815ed 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -619,10 +619,10 @@ def test_columns_and_col_order(self, project_id): # Verify that col_order is prioritized over columns assert sorted(col_order) == sorted(result_frame.columns) - + def test_col_order_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" - columns = ["string_2", "string_1", "string_3"] + columns = ["string_2", "string_1", "string_3"] # Not explicitly specifying col_order result_frame = gbq.read_gbq( From 597b4c83387ddc72e23bc22d9fb6318917dda610 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 27 Nov 2023 14:40:37 -0800 Subject: [PATCH 04/15] refactored to alias checking and testing --- docs/reading.rst | 1 - pandas_gbq/gbq.py | 15 +++++++++------ tests/system/test_gbq.py | 41 +++++++++++++++++----------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/docs/reading.rst b/docs/reading.rst index a1ba0a5e..6361280a 100644 --- a/docs/reading.rst +++ b/docs/reading.rst @@ -28,7 +28,6 @@ destination DataFrame as well as a preferred column order as follows: 'SELECT * FROM `test_dataset.test_table`', project_id=projectid, index_col='index_column_name', - col_order=['col1', 'col2', 'col3'], columns=['col1', 'col2']) Querying with legacy SQL syntax diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index 9f091d0b..983b2567 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -776,7 +776,7 @@ def read_gbq( List of BigQuery column names in the desired order for results DataFrame. columns : list(str), optional - List of BigQuery column names to return, alias for col_order + Alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. @@ -967,13 +967,16 @@ def read_gbq( 'Index column "{0}" does not exist in DataFrame.'.format(index_col) ) - # Creating an alias for col_order, which is columns - col_order = col_order or columns + # Using columns as an alias for col_order, raising an error if both provided + if col_order and not columns: + columns = col_order + elif col_order and columns: + raise ValueError("Must specify either columns or col_order, not both") # Change the order of columns in the DataFrame based on provided list - if col_order is not None: - if sorted(col_order) == sorted(final_df.columns): - final_df = final_df[col_order] + if columns is not None: + if sorted(columns) == sorted(final_df.columns): + final_df = final_df[columns] else: raise InvalidColumnOrder("Column order does not match this DataFrame.") diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 076815ed..0fd97941 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -600,30 +600,9 @@ def test_tokyo(self, tokyo_dataset, tokyo_table, project_id): ) assert df["max_year"][0] >= 2000 - def test_columns_and_col_order(self, project_id): - query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" - columns = ["string_2", "string_1"] - col_order = ["string_3", "string_1", "string_2"] - result_frame = gbq.read_gbq( - query, - project_id=project_id, - columns=columns, - col_order=col_order, - credentials=self.credentials, - dialect="standard", - ) - correct_frame = DataFrame( - {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} - )[col_order] - tm.assert_frame_equal(result_frame, correct_frame) - - # Verify that col_order is prioritized over columns - assert sorted(col_order) == sorted(result_frame.columns) - - def test_col_order_as_alias(self, project_id): + def test_columns_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" columns = ["string_2", "string_1", "string_3"] - # Not explicitly specifying col_order result_frame = gbq.read_gbq( query, @@ -640,8 +619,22 @@ def test_col_order_as_alias(self, project_id): # Verify that the result_frame matches the expected DataFrame tm.assert_frame_equal(result_frame, correct_frame) - # Ensure that the order of columns in the result_frame matches the specified order - assert sorted(columns) == sorted(result_frame.columns) + assert columns == result_frame.columns + + def test_columns_and_col_order_raises_error(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1"] + col_order = ["string_3", "string_1", "string_2"] + + with pytest.raises(ValueError): + gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + col_order=col_order, + credentials=self.credentials, + dialect="standard", + ) class TestToGBQIntegration(object): From fa83832ec79cb7220919ec2c677949a21d9cb763 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 27 Nov 2023 14:59:01 -0800 Subject: [PATCH 05/15] Reformatted tests for columns alias --- tests/system/test_gbq.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 0fd97941..bc078264 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -604,7 +604,7 @@ def test_columns_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" columns = ["string_2", "string_1", "string_3"] - result_frame = gbq.read_gbq( + df = gbq.read_gbq( query, project_id=project_id, columns=columns, @@ -612,14 +612,12 @@ def test_columns_as_alias(self, project_id): dialect="standard", ) - correct_frame = DataFrame( - {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} - )[columns] + expected = DataFrame({"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]})[ + columns + ] # Verify that the result_frame matches the expected DataFrame - tm.assert_frame_equal(result_frame, correct_frame) - - assert columns == result_frame.columns + tm.assert_frame_equal(df, expected) def test_columns_and_col_order_raises_error(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" From fc42a1d7a79ec49770ed6a6bb1f8fee5da288014 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 19:47:00 -0800 Subject: [PATCH 06/15] feat: add 'columns' as an alias for 'col_order' --- docs/reading.rst | 3 ++- pandas_gbq/gbq.py | 6 ++++++ tests/system/test_gbq.py | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/reading.rst b/docs/reading.rst index c5e814bf..a1ba0a5e 100644 --- a/docs/reading.rst +++ b/docs/reading.rst @@ -28,7 +28,8 @@ destination DataFrame as well as a preferred column order as follows: 'SELECT * FROM `test_dataset.test_table`', project_id=projectid, index_col='index_column_name', - col_order=['col1', 'col2', 'col3']) + col_order=['col1', 'col2', 'col3'], + columns=['col1', 'col2']) Querying with legacy SQL syntax ------------------------------- diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index 3d43884a..abbe3f26 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -735,6 +735,7 @@ def read_gbq( project_id=None, index_col=None, col_order=None, + columns=None, reauth=False, auth_local_webserver=True, dialect=None, @@ -776,6 +777,8 @@ def read_gbq( col_order : list(str), optional List of BigQuery column names in the desired order for results DataFrame. + columns : list(str), optional + List of BigQuery column names to return, alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. @@ -966,6 +969,9 @@ def read_gbq( 'Index column "{0}" does not exist in DataFrame.'.format(index_col) ) + # Creating an alias for col_order, which is columns + col_order = col_order or columns + # Change the order of columns in the DataFrame based on provided list if col_order is not None: if sorted(col_order) == sorted(final_df.columns): diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 9aac2357..183bcb8a 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -600,6 +600,26 @@ def test_tokyo(self, tokyo_dataset, tokyo_table, project_id): ) assert df["max_year"][0] >= 2000 + def test_columns_and_col_order(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1"] + col_order = ["string_3", "string_1", "string_2"] + result_frame = gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + col_order=col_order, + credentials=self.credentials, + dialect="standard", + ) + correct_frame = DataFrame( + {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} + )[col_order] + tm.assert_frame_equal(result_frame, correct_frame) + + # Verify that col_order is prioritized over columns + assert sorted(col_order) == sorted(result_frame.columns) + class TestToGBQIntegration(object): @pytest.fixture(autouse=True, scope="function") From 5643cf41d446455f02faf54e7fdf15fae6b2f613 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 20:16:00 -0800 Subject: [PATCH 07/15] Added test to test alias correctness --- tests/system/test_gbq.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 183bcb8a..3fc985eb 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -619,6 +619,29 @@ def test_columns_and_col_order(self, project_id): # Verify that col_order is prioritized over columns assert sorted(col_order) == sorted(result_frame.columns) + + def test_col_order_as_alias(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1", "string_3"] + # Not explicitly specifying col_order + + result_frame = gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + credentials=self.credentials, + dialect="standard", + ) + + correct_frame = DataFrame( + {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} + )[columns] + + # Verify that the result_frame matches the expected DataFrame + tm.assert_frame_equal(result_frame, correct_frame) + + # Ensure that the order of columns in the result_frame matches the specified order + assert sorted(columns) == sorted(result_frame.columns) class TestToGBQIntegration(object): From e51d010f6dc0b802cca665bd89a02cecd54384e1 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 20 Nov 2023 20:16:44 -0800 Subject: [PATCH 08/15] reformatted with black --- tests/system/test_gbq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 3fc985eb..076815ed 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -619,10 +619,10 @@ def test_columns_and_col_order(self, project_id): # Verify that col_order is prioritized over columns assert sorted(col_order) == sorted(result_frame.columns) - + def test_col_order_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" - columns = ["string_2", "string_1", "string_3"] + columns = ["string_2", "string_1", "string_3"] # Not explicitly specifying col_order result_frame = gbq.read_gbq( From 984c353552b413c3466b134cd9f1d127ce3f9a3f Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 27 Nov 2023 14:40:37 -0800 Subject: [PATCH 09/15] refactored to alias checking and testing --- docs/reading.rst | 1 - pandas_gbq/gbq.py | 15 +++++++++------ tests/system/test_gbq.py | 41 +++++++++++++++++----------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/docs/reading.rst b/docs/reading.rst index a1ba0a5e..6361280a 100644 --- a/docs/reading.rst +++ b/docs/reading.rst @@ -28,7 +28,6 @@ destination DataFrame as well as a preferred column order as follows: 'SELECT * FROM `test_dataset.test_table`', project_id=projectid, index_col='index_column_name', - col_order=['col1', 'col2', 'col3'], columns=['col1', 'col2']) Querying with legacy SQL syntax diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index abbe3f26..31388f6b 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -778,7 +778,7 @@ def read_gbq( List of BigQuery column names in the desired order for results DataFrame. columns : list(str), optional - List of BigQuery column names to return, alias for col_order + Alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. @@ -969,13 +969,16 @@ def read_gbq( 'Index column "{0}" does not exist in DataFrame.'.format(index_col) ) - # Creating an alias for col_order, which is columns - col_order = col_order or columns + # Using columns as an alias for col_order, raising an error if both provided + if col_order and not columns: + columns = col_order + elif col_order and columns: + raise ValueError("Must specify either columns or col_order, not both") # Change the order of columns in the DataFrame based on provided list - if col_order is not None: - if sorted(col_order) == sorted(final_df.columns): - final_df = final_df[col_order] + if columns is not None: + if sorted(columns) == sorted(final_df.columns): + final_df = final_df[columns] else: raise InvalidColumnOrder("Column order does not match this DataFrame.") diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 076815ed..0fd97941 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -600,30 +600,9 @@ def test_tokyo(self, tokyo_dataset, tokyo_table, project_id): ) assert df["max_year"][0] >= 2000 - def test_columns_and_col_order(self, project_id): - query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" - columns = ["string_2", "string_1"] - col_order = ["string_3", "string_1", "string_2"] - result_frame = gbq.read_gbq( - query, - project_id=project_id, - columns=columns, - col_order=col_order, - credentials=self.credentials, - dialect="standard", - ) - correct_frame = DataFrame( - {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} - )[col_order] - tm.assert_frame_equal(result_frame, correct_frame) - - # Verify that col_order is prioritized over columns - assert sorted(col_order) == sorted(result_frame.columns) - - def test_col_order_as_alias(self, project_id): + def test_columns_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" columns = ["string_2", "string_1", "string_3"] - # Not explicitly specifying col_order result_frame = gbq.read_gbq( query, @@ -640,8 +619,22 @@ def test_col_order_as_alias(self, project_id): # Verify that the result_frame matches the expected DataFrame tm.assert_frame_equal(result_frame, correct_frame) - # Ensure that the order of columns in the result_frame matches the specified order - assert sorted(columns) == sorted(result_frame.columns) + assert columns == result_frame.columns + + def test_columns_and_col_order_raises_error(self, project_id): + query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" + columns = ["string_2", "string_1"] + col_order = ["string_3", "string_1", "string_2"] + + with pytest.raises(ValueError): + gbq.read_gbq( + query, + project_id=project_id, + columns=columns, + col_order=col_order, + credentials=self.credentials, + dialect="standard", + ) class TestToGBQIntegration(object): From ef66ac3d33fb5b4514a4e99ef0b438d1031571ed Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 27 Nov 2023 14:59:01 -0800 Subject: [PATCH 10/15] Reformatted tests for columns alias --- tests/system/test_gbq.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/system/test_gbq.py b/tests/system/test_gbq.py index 0fd97941..bc078264 100644 --- a/tests/system/test_gbq.py +++ b/tests/system/test_gbq.py @@ -604,7 +604,7 @@ def test_columns_as_alias(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" columns = ["string_2", "string_1", "string_3"] - result_frame = gbq.read_gbq( + df = gbq.read_gbq( query, project_id=project_id, columns=columns, @@ -612,14 +612,12 @@ def test_columns_as_alias(self, project_id): dialect="standard", ) - correct_frame = DataFrame( - {"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]} - )[columns] + expected = DataFrame({"string_1": ["a"], "string_2": ["b"], "string_3": ["c"]})[ + columns + ] # Verify that the result_frame matches the expected DataFrame - tm.assert_frame_equal(result_frame, correct_frame) - - assert columns == result_frame.columns + tm.assert_frame_equal(df, expected) def test_columns_and_col_order_raises_error(self, project_id): query = "SELECT 'a' AS string_1, 'b' AS string_2, 'c' AS string_3" From 6d7f8219bd2277ff70a218878f00fdcdef066cc0 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Tue, 28 Nov 2023 13:22:00 -0800 Subject: [PATCH 11/15] Made col_order a keyword argument and added to-do --- pandas_gbq/gbq.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index 31388f6b..8f5a7e72 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -734,7 +734,6 @@ def read_gbq( query_or_table, project_id=None, index_col=None, - col_order=None, columns=None, reauth=False, auth_local_webserver=True, @@ -751,6 +750,8 @@ def read_gbq( auth_redirect_uri=None, client_id=None, client_secret=None, + *, + col_order=None, ): r"""Load data from Google BigQuery using google-cloud-python @@ -774,11 +775,9 @@ def read_gbq( the environment. index_col : str, optional Name of result column to use for index in results DataFrame. - col_order : list(str), optional + columns : list(str), optional List of BigQuery column names in the desired order for results DataFrame. - columns : list(str), optional - Alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. @@ -891,6 +890,8 @@ def read_gbq( client_secret : str The Client Secret associated with the Client ID for the Google Cloud Project the user is attempting to connect to. + col_order : list(str), optional + Alias for columns, retained for backwards compatibility. Returns ------- @@ -976,6 +977,7 @@ def read_gbq( raise ValueError("Must specify either columns or col_order, not both") # Change the order of columns in the DataFrame based on provided list + # TO DO: allow columns to be a subset of all columns in the table, with follow up PR if columns is not None: if sorted(columns) == sorted(final_df.columns): final_df = final_df[columns] From 653e93e3ce1060352643aa9b713c6d5af18fb296 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Tue, 28 Nov 2023 13:26:46 -0800 Subject: [PATCH 12/15] Edit todo comment --- pandas_gbq/gbq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index 8f5a7e72..dbb9a87e 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -977,7 +977,7 @@ def read_gbq( raise ValueError("Must specify either columns or col_order, not both") # Change the order of columns in the DataFrame based on provided list - # TO DO: allow columns to be a subset of all columns in the table, with follow up PR + # TODO(kiraksi): allow columns to be a subset of all columns in the table, with follow up PR if columns is not None: if sorted(columns) == sorted(final_df.columns): final_df = final_df[columns] From f22f95cad35e54b6d9d591b0bef8105871cbd3db Mon Sep 17 00:00:00 2001 From: kiraksi Date: Tue, 28 Nov 2023 13:35:26 -0800 Subject: [PATCH 13/15] Fixed small error in docstring --- pandas_gbq/gbq.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index c8574d49..dbb9a87e 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -778,8 +778,6 @@ def read_gbq( columns : list(str), optional List of BigQuery column names in the desired order for results DataFrame. - columns : list(str), optional - Alias for col_order reauth : boolean, default False Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used. From 3a5368bee544fc7cfc9ce203ae9fbe9025a180f6 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Fri, 1 Dec 2023 17:24:24 -0800 Subject: [PATCH 14/15] Fixed valueerror message --- pandas_gbq/gbq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index dbb9a87e..cebcad5c 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -974,7 +974,7 @@ def read_gbq( if col_order and not columns: columns = col_order elif col_order and columns: - raise ValueError("Must specify either columns or col_order, not both") + raise ValueError("Must specify either columns (preferred) or col_order, not both") # Change the order of columns in the DataFrame based on provided list # TODO(kiraksi): allow columns to be a subset of all columns in the table, with follow up PR From b71b407a227ddb5a2bb9ed6d2abd0c36fba76076 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Fri, 1 Dec 2023 17:36:44 -0800 Subject: [PATCH 15/15] reformatted with black --- pandas_gbq/gbq.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index cebcad5c..d4a8d2b7 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -974,7 +974,9 @@ def read_gbq( if col_order and not columns: columns = col_order elif col_order and columns: - raise ValueError("Must specify either columns (preferred) or col_order, not both") + raise ValueError( + "Must specify either columns (preferred) or col_order, not both" + ) # Change the order of columns in the DataFrame based on provided list # TODO(kiraksi): allow columns to be a subset of all columns in the table, with follow up PR