Skip to content
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

deps: make pyarrow and BQ Storage optional dependencies #1282

Merged
merged 62 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
b7e2cbb
update dependencies
steffnay Jun 30, 2022
951a43e
Merge branch 'main' of github.com:googleapis/python-bigquery into py-…
steffnay Jul 8, 2022
e9c57d6
deps: pyarrow extras
steffnay Jul 8, 2022
47a489b
clean up comments
steffnay Jul 8, 2022
fd0c40c
add test pyarrow skips
steffnay Jul 8, 2022
85db3e5
Merge branch 'main' into py-extra
parthea Jul 9, 2022
1fac4d2
replace storage checks
steffnay Jul 11, 2022
eaada14
Merge branch 'main' of github.com:googleapis/python-bigquery into py-…
steffnay Jul 11, 2022
61c69e9
update tests
steffnay Jul 11, 2022
95da5c7
Merge branch 'py-extra' of github.com:steffnay/python-bigquery into p…
steffnay Jul 11, 2022
e31e4ef
update tests
steffnay Jul 11, 2022
b4f7160
Update setup.py
steffnay Jul 11, 2022
2bb6461
update system tests
steffnay Jul 12, 2022
2602e4d
Merge branch 'py-extra' of github.com:steffnay/python-bigquery into p…
steffnay Jul 12, 2022
3a87275
update verify_pandas_imports
steffnay Jul 14, 2022
e0a9a2a
add pyarrow guards
steffnay Jul 14, 2022
f3dbaea
add datetime check
steffnay Jul 15, 2022
91fccef
change pyarrow import
steffnay Jul 15, 2022
ac78a33
update
steffnay Jul 15, 2022
0d89234
add pyarrow skips
steffnay Jul 21, 2022
b774b4b
merge
steffnay Jul 21, 2022
79dd4cc
fix types
steffnay Jul 21, 2022
37d7a25
lint
steffnay Jul 21, 2022
9dedf78
Update google/cloud/bigquery/client.py
steffnay Aug 1, 2022
933963e
update pyarrow version
steffnay Aug 1, 2022
93d7639
Merge branch 'py-extra' of github.com:steffnay/python-bigquery into p…
steffnay Aug 1, 2022
45eed33
update test
steffnay Aug 1, 2022
6ac7204
Merge branch 'main' into py-extra
steffnay Aug 1, 2022
af00605
lint
steffnay Aug 1, 2022
5bd1f30
Merge branch 'py-extra' of github.com:steffnay/python-bigquery into p…
steffnay Aug 1, 2022
ef20ab5
update pyarrow req
steffnay Aug 1, 2022
95aceca
update noxfile
steffnay Aug 1, 2022
12591b3
Merge branch 'main' into py-extra
steffnay Aug 5, 2022
d0e9045
remove bignum check
steffnay Aug 5, 2022
5045ead
remove comments
steffnay Aug 5, 2022
050af79
Merge branch 'main' into py-extra
steffnay Aug 18, 2022
01dd2b2
Merge branch 'main' of github.com:googleapis/python-bigquery into py-…
steffnay Sep 23, 2022
1eb5fac
add test importorskip
steffnay Sep 23, 2022
f23657b
update test
steffnay Sep 24, 2022
7138f1e
update test
steffnay Sep 24, 2022
abb9b8c
update dependency
steffnay Sep 24, 2022
d69f8ad
change version
steffnay Sep 24, 2022
caa21cb
update imports
steffnay Sep 26, 2022
17d922a
Merge branch 'main' into py-extra
steffnay Oct 3, 2022
d52b301
Merge branch 'main' into py-extra
steffnay Dec 6, 2022
21ebf7d
adjust test expectations when google-cloud-bigquery-storage is not av…
tswast Dec 8, 2022
39b173a
export pyarrow exception
tswast Dec 8, 2022
88fa115
whitespace in docstrings
tswast Dec 8, 2022
1b926aa
format minimum bqstorage version string
tswast Dec 8, 2022
d71141d
restore optional bqstorage_client
tswast Dec 8, 2022
51332d1
restore optional bqstorage_client (in table.py)
tswast Dec 8, 2022
4c296ae
synchronize constraints and setup.py
tswast Dec 8, 2022
6067f90
synchronize signatures
tswast Dec 8, 2022
6c2b8a5
remove unnecessary bignumeric_type extra
tswast Dec 8, 2022
8196a15
more constraints sync
tswast Dec 8, 2022
5bac083
remove unnecessary mock
tswast Dec 8, 2022
dafdb64
fix unittest skip
tswast Dec 8, 2022
805f5d3
synchronize constraints
tswast Dec 8, 2022
b85dcf3
adjust shapely
tswast Dec 8, 2022
bf4f218
simplify with importorskip
tswast Dec 8, 2022
794f70c
blacken
tswast Dec 8, 2022
bab28b5
Merge branch 'main' into py-extra
tswast Dec 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
steffnay committed Jul 15, 2022
commit ac78a3380ce0a21044362b0e181500a0ba21bfba
24 changes: 12 additions & 12 deletions google/cloud/bigquery/_pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@
date_dtype_name = time_dtype_name = "" # Use '' rather than None because pytype

try:
import pyarrow # type: ignore
import pyarrow.parquet # type: ignore

pyarrow_import_exception = None
except ImportError as exc: # pragma: NO COVER
import pyarrow
import pyarrow.parquet
except ImportError: # pragma: NO COVER
pyarrow = None
pyarrow_import_exception = exc

try:
# _BaseGeometry is used to detect shapely objevys in `bq_to_arrow_array`
Expand Down Expand Up @@ -93,6 +90,7 @@ def _to_wkb(v):

from google.cloud.bigquery import schema

pyarrow = _helpers.PYARROW_VERSIONS.try_import()

_LOGGER = logging.getLogger(__name__)

Expand All @@ -104,6 +102,11 @@ def _to_wkb(v):
_NO_DB_TYPES_ERROR = "Please install the 'db-dtypes' package to use this function."
_NO_PYARROW_ERROR = "Please install the 'pyarrow' package to use this function."

_NO_BQSTORAGE_ERROR = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to move this to BQStorageVersions in the verify_version method. It could first check if the package is not installed at all?

Likewise, we could add a verify_version method to PyarrowVersions that raises if the package is not installed and not at the right version.

"The google-cloud-bigquery-storage library is not installed, "
"please install google-cloud-bigquery-storage to use bqstorage features."
)

_PANDAS_DTYPE_TO_BQ = {
"bool": "BOOLEAN",
"datetime64[ns, UTC]": "TIMESTAMP",
Expand Down Expand Up @@ -691,10 +694,9 @@ def dataframe_to_parquet(

This argument is ignored for ``pyarrow`` versions earlier than ``4.0.0``.
"""
global pyarrow
if pyarrow is None:
raise ValueError("pyarrow is required for BigQuery schema conversion.")
import pyarrow.parquet # type: ignore
pyarrow = _helpers.PYARROW_VERSIONS.try_import(raise_if_error=True)

import pyarrow.parquet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we do this here, we can remove the try/except above, right?


kwargs = (
{"use_compliant_nested_type": parquet_use_compliant_nested_type}
Expand Down Expand Up @@ -1019,8 +1021,6 @@ def dataframe_to_json_generator(dataframe):


def verify_pandas_imports():
if pyarrow is None:
raise ValueError(_NO_PYARROW_ERROR) from pyarrow_import_exception
if pandas is None:
raise ValueError(_NO_PANDAS_ERROR) from pandas_import_exception
if db_dtypes is None:
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/job/test_query_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
# import google.cloud.bigquery_storage_v1.reader
# import google.cloud.bigquery_storage_v1.services.big_query_read.client

try:
import pyarrow
except (ImportError, AttributeError): # pragma: NO COVER
pyarrow = None

try:
from google.cloud import bigquery_storage
import google.cloud.bigquery_storage_v1.reader
import google.cloud.bigquery_storage_v1.services.big_query_read.client
except (ImportError, AttributeError): # pragma: NO COVER
bigquery_storage = None

from google.cloud.bigquery import _helpers

try:
import pandas
except (ImportError, AttributeError): # pragma: NO COVER
Expand All @@ -56,6 +55,8 @@

pandas = pytest.importorskip("pandas")

pyarrow = _helpers.PYARROW_VERSIONS.try_import()


@pytest.fixture
def table_read_options_kwarg():
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test__pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
from google.cloud.bigquery import schema
from google.cloud.bigquery._pandas_helpers import _BIGNUMERIC_SUPPORT

try:
import pyarrow
pyarrow = _helpers.PYARROW_VERSIONS.try_import()
if pyarrow:
import pyarrow.types
except ImportError: # pragma: NO COVER
else: # pragma: NO COVER
# Mock out pyarrow when missing, because methods from pyarrow.types are
# used in test parameterization.
pyarrow = mock.Mock()
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_dbapi__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

import pytest

try:
import pyarrow
except ImportError: # pragma: NO COVER
pyarrow = None

import google.cloud._helpers
from google.cloud.bigquery import query, table
from google.cloud.bigquery.dbapi import _helpers
Expand Down Expand Up @@ -210,6 +215,7 @@ def test_empty_iterable(self):
result = _helpers.to_bq_table_rows(rows_iterable)
self.assertEqual(list(result), [])

@unittest.skipIf(pyarrow is None, "Requires `pyarrow`")
def test_non_empty_iterable(self):
rows_iterable = [
dict(
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from test_utils.imports import maybe_fail_import

from google.cloud.bigquery.table import TableReference
from google.cloud.bigquery.dataset import DatasetReference

try:
from google.cloud import bigquery_storage
Expand All @@ -38,14 +39,15 @@
bigquery_storage = None
big_query_read_grpc_transport = None

try:
import pyarrow
from google.cloud.bigquery import _helpers


pyarrow = _helpers.PYARROW_VERSIONS.try_import()
PYARROW_VERSION = pkg_resources.parse_version("0.0.1")
if pyarrow:
import pyarrow.types

PYARROW_VERSION = pkg_resources.parse_version(pyarrow.__version__)
except ImportError: # pragma: NO COVER
pyarrow = None
PYARROW_VERSION = pkg_resources.parse_version("0.0.1")

try:
import pandas
Expand All @@ -62,8 +64,6 @@
except (ImportError, AttributeError): # pragma: NO COVER
tqdm = None

from google.cloud.bigquery.dataset import DatasetReference

PYARROW_TIMESTAMP_VERSION = pkg_resources.parse_version("2.0.0")


Expand Down