Commit 4f67ba2
authored
fix: add timeout parameter to to_dataframe and to_arrow met… (#2354)
### Description
This PR adds a `timeout` parameter to the `to_dataframe()` and
`to_arrow()` methods (and their corresponding `*_iterable`,
`*_geodataframe` and `QueryJob` wrappers) in the BigQuery client
library.
This addresses an issue where these methods could hang indefinitely if
the underlying BigQuery Storage API stream blocked (e.g., due to
firewall issues or network interruptions) during the download phase. The
added `timeout` parameter ensures that the download operation respects
the specified time limit and raises a `concurrent.futures.TimeoutError`
if it exceeds the duration.
### Changes
- Modified `google/cloud/bigquery/_pandas_helpers.py`:
- Updated `_download_table_bqstorage` to accept a `timeout` argument.
- Implemented a timeout check within the result processing loop.
- Updated wrapper functions `download_dataframe_bqstorage` and
`download_arrow_bqstorage` to accept and pass the `timeout` parameter.
- Modified `google/cloud/bigquery/table.py`:
- Updated `RowIterator` methods (`to_arrow_iterable`, `to_arrow`,
`to_dataframe_iterable`, `to_dataframe`, `to_geodataframe`) to accept
and pass `timeout`.
- Updated `_EmptyRowIterator` methods to match the `RowIterator`
signature, preventing `TypeError` when a timeout is provided for empty
result sets.
- Modified `google/cloud/bigquery/job/query.py`:
- Updated `QueryJob` methods (`to_arrow`, `to_dataframe`,
`to_geodataframe`) to accept `timeout` and pass it to the result
iterator.
- Updated unit tests in `tests/unit/job/test_query_pandas.py`,
`tests/unit/test_table.py`, and `tests/unit/test_table_pandas.py` to
reflect the signature changes.
Fixes internal bug: b/4680913071 parent 40b4cbf commit 4f67ba2
File tree
7 files changed
+257
-55
lines changed- google/cloud/bigquery
- job
- tests/unit
- job
7 files changed
+257
-55
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
869 | 870 | | |
870 | 871 | | |
871 | 872 | | |
| 873 | + | |
872 | 874 | | |
873 | 875 | | |
874 | 876 | | |
| |||
899 | 901 | | |
900 | 902 | | |
901 | 903 | | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
902 | 907 | | |
903 | 908 | | |
904 | 909 | | |
905 | 910 | | |
906 | 911 | | |
907 | 912 | | |
908 | 913 | | |
| 914 | + | |
| 915 | + | |
909 | 916 | | |
910 | 917 | | |
911 | 918 | | |
| |||
973 | 980 | | |
974 | 981 | | |
975 | 982 | | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
1007 | 987 | | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1013 | 1033 | | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1026 | 1046 | | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
1030 | 1050 | | |
1031 | 1051 | | |
1032 | 1052 | | |
| |||
1037 | 1057 | | |
1038 | 1058 | | |
1039 | 1059 | | |
| 1060 | + | |
1040 | 1061 | | |
1041 | 1062 | | |
1042 | 1063 | | |
| |||
1047 | 1068 | | |
1048 | 1069 | | |
1049 | 1070 | | |
| 1071 | + | |
1050 | 1072 | | |
1051 | 1073 | | |
1052 | 1074 | | |
| |||
1060 | 1082 | | |
1061 | 1083 | | |
1062 | 1084 | | |
| 1085 | + | |
1063 | 1086 | | |
1064 | 1087 | | |
1065 | 1088 | | |
| |||
1071 | 1094 | | |
1072 | 1095 | | |
1073 | 1096 | | |
| 1097 | + | |
1074 | 1098 | | |
1075 | 1099 | | |
1076 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1857 | 1857 | | |
1858 | 1858 | | |
1859 | 1859 | | |
| 1860 | + | |
1860 | 1861 | | |
1861 | 1862 | | |
1862 | 1863 | | |
| |||
1904 | 1905 | | |
1905 | 1906 | | |
1906 | 1907 | | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
1907 | 1912 | | |
1908 | 1913 | | |
1909 | 1914 | | |
| |||
1921 | 1926 | | |
1922 | 1927 | | |
1923 | 1928 | | |
| 1929 | + | |
1924 | 1930 | | |
1925 | 1931 | | |
1926 | 1932 | | |
| |||
1949 | 1955 | | |
1950 | 1956 | | |
1951 | 1957 | | |
| 1958 | + | |
1952 | 1959 | | |
1953 | 1960 | | |
1954 | 1961 | | |
| |||
2141 | 2148 | | |
2142 | 2149 | | |
2143 | 2150 | | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
2144 | 2155 | | |
2145 | 2156 | | |
2146 | 2157 | | |
| |||
2174 | 2185 | | |
2175 | 2186 | | |
2176 | 2187 | | |
| 2188 | + | |
2177 | 2189 | | |
2178 | 2190 | | |
2179 | 2191 | | |
| |||
2191 | 2203 | | |
2192 | 2204 | | |
2193 | 2205 | | |
| 2206 | + | |
2194 | 2207 | | |
2195 | 2208 | | |
2196 | 2209 | | |
| |||
2269 | 2282 | | |
2270 | 2283 | | |
2271 | 2284 | | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
2272 | 2288 | | |
2273 | 2289 | | |
2274 | 2290 | | |
| |||
2296 | 2312 | | |
2297 | 2313 | | |
2298 | 2314 | | |
| 2315 | + | |
2299 | 2316 | | |
2300 | 2317 | | |
2301 | 2318 | | |
| |||
0 commit comments