This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Commit 4333910
authored
fix(deps): raise exception when pandas is installed but db-dtypes is not (#1191)
`db-dtypes` is already present in the `pandas` "extras", but this PR ensures that if pandas is present and db-dtypes is not, a more understandable error message is raised.
```
google/cloud/bigquery/_pandas_helpers.py:991: ValueError
____________________________________ test_list_rows_nullable_scalars_extreme_dtypes[10] _____________________________________
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Shared helper functions for connecting BigQuery and pandas."""
import concurrent.futures
from datetime import datetime
import functools
from itertools import islice
import logging
import queue
import warnings
try:
import pandas # type: ignore
pandas_import_exception = None
except ImportError as exc: # pragma: NO COVER
pandas = None
pandas_import_exception = exc
else:
import numpy
try:
> import db_dtypes # type: ignore
E ModuleNotFoundError: No module named 'db_dtypes'
google/cloud/bigquery/_pandas_helpers.py:36: ModuleNotFoundError
The above exception was the direct cause of the following exception:
bigquery_client = <google.cloud.bigquery.client.Client object at 0x11e2d3580>
scalars_extreme_table = 'swast-scratch.python_bigquery_tests_system_20220330160830_ffff89.scalars_extreme_jsonl0x3ffeb'
max_results = 10
@pytest.mark.parametrize(
("max_results",),
(
(None,),
(10,),
), # Use BQ Storage API. # Use REST API.
)
def test_list_rows_nullable_scalars_extreme_dtypes(
bigquery_client, scalars_extreme_table, max_results
):
# TODO(GH#836): Avoid INTERVAL columns until they are supported by the
# BigQuery Storage API and pyarrow.
schema = [
bigquery.SchemaField("bool_col", enums.SqlTypeNames.BOOLEAN),
bigquery.SchemaField("bignumeric_col", enums.SqlTypeNames.BIGNUMERIC),
bigquery.SchemaField("bytes_col", enums.SqlTypeNames.BYTES),
bigquery.SchemaField("date_col", enums.SqlTypeNames.DATE),
bigquery.SchemaField("datetime_col", enums.SqlTypeNames.DATETIME),
bigquery.SchemaField("float64_col", enums.SqlTypeNames.FLOAT64),
bigquery.SchemaField("geography_col", enums.SqlTypeNames.GEOGRAPHY),
bigquery.SchemaField("int64_col", enums.SqlTypeNames.INT64),
bigquery.SchemaField("numeric_col", enums.SqlTypeNames.NUMERIC),
bigquery.SchemaField("string_col", enums.SqlTypeNames.STRING),
bigquery.SchemaField("time_col", enums.SqlTypeNames.TIME),
bigquery.SchemaField("timestamp_col", enums.SqlTypeNames.TIMESTAMP),
]
df = bigquery_client.list_rows(
scalars_extreme_table,
max_results=max_results,
selected_fields=schema,
> ).to_dataframe()
tests/system/test_pandas.py:1084:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
google/cloud/bigquery/table.py:1925: in to_dataframe
_pandas_helpers.verify_pandas_imports()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def verify_pandas_imports():
if pandas is None:
raise ValueError(_NO_PANDAS_ERROR) from pandas_import_exception
if db_dtypes is None:
> raise ValueError(_NO_DB_TYPES_ERROR) from db_dtypes_import_exception
E ValueError: Please install the 'db-dtypes' package to use this function.
google/cloud/bigquery/_pandas_helpers.py:991: ValueError
```
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
Fixes #1188 🦕1 parent b4c7f5a commit 4333910
File tree
4 files changed
+49
-25
lines changed- google/cloud/bigquery
- tests/unit
4 files changed
+49
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
34 | 45 | | |
35 | | - | |
36 | | - | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
| |||
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 | | |
88 | 100 | | |
89 | 101 | | |
| |||
290 | 302 | | |
291 | 303 | | |
292 | 304 | | |
293 | | - | |
| 305 | + | |
294 | 306 | | |
295 | 307 | | |
296 | 308 | | |
297 | 309 | | |
298 | 310 | | |
299 | | - | |
| 311 | + | |
300 | 312 | | |
301 | 313 | | |
302 | 314 | | |
| |||
970 | 982 | | |
971 | 983 | | |
972 | 984 | | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
| |||
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 70 | | |
77 | 71 | | |
78 | 72 | | |
| |||
1818 | 1812 | | |
1819 | 1813 | | |
1820 | 1814 | | |
1821 | | - | |
1822 | | - | |
| 1815 | + | |
| 1816 | + | |
1823 | 1817 | | |
1824 | 1818 | | |
1825 | 1819 | | |
| |||
1928 | 1922 | | |
1929 | 1923 | | |
1930 | 1924 | | |
1931 | | - | |
1932 | | - | |
| 1925 | + | |
| 1926 | + | |
1933 | 1927 | | |
1934 | 1928 | | |
1935 | 1929 | | |
| |||
2181 | 2175 | | |
2182 | 2176 | | |
2183 | 2177 | | |
2184 | | - | |
2185 | | - | |
| 2178 | + | |
2186 | 2179 | | |
2187 | 2180 | | |
2188 | 2181 | | |
| |||
2238 | 2231 | | |
2239 | 2232 | | |
2240 | 2233 | | |
2241 | | - | |
2242 | | - | |
| 2234 | + | |
2243 | 2235 | | |
2244 | 2236 | | |
2245 | 2237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1751 | 1751 | | |
1752 | 1752 | | |
1753 | 1753 | | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1836 | 1836 | | |
1837 | 1837 | | |
1838 | 1838 | | |
1839 | | - | |
| 1839 | + | |
1840 | 1840 | | |
1841 | 1841 | | |
1842 | 1842 | | |
| |||
1849 | 1849 | | |
1850 | 1850 | | |
1851 | 1851 | | |
1852 | | - | |
| 1852 | + | |
1853 | 1853 | | |
1854 | 1854 | | |
1855 | 1855 | | |
| |||
2967 | 2967 | | |
2968 | 2968 | | |
2969 | 2969 | | |
2970 | | - | |
| 2970 | + | |
2971 | 2971 | | |
2972 | 2972 | | |
2973 | 2973 | | |
| |||
3339 | 3339 | | |
3340 | 3340 | | |
3341 | 3341 | | |
3342 | | - | |
| 3342 | + | |
3343 | 3343 | | |
3344 | 3344 | | |
3345 | 3345 | | |
| |||
0 commit comments