Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21714e1

Browse files
authored
fix: makepyarrow an optional dependency post-3.20.0 yanked release (#1879)
* fix: make `pyarrow` an optional dependency again* install older version of pyarrow* fix for older tqdm* remove many pragma: NO COVERs
1 parent7dfee0c commit21714e1

21 files changed

+126
-100
lines changed

‎google/cloud/bigquery/_pandas_helpers.py‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
importpandas# type: ignore
3333

3434
pandas_import_exception=None
35-
exceptImportErrorasexc:# pragma: NO COVER
35+
exceptImportErrorasexc:
3636
pandas=None
3737
pandas_import_exception=exc
3838
else:
@@ -44,25 +44,21 @@
4444
date_dtype_name=db_dtypes.DateDtype.name
4545
time_dtype_name=db_dtypes.TimeDtype.name
4646
db_dtypes_import_exception=None
47-
exceptImportErrorasexc:# pragma: NO COVER
47+
exceptImportErrorasexc:
4848
db_dtypes=None
4949
db_dtypes_import_exception=exc
5050
date_dtype_name=time_dtype_name=""# Use '' rather than None because pytype
5151

52-
pyarrow=_versions_helpers.PYARROW_VERSIONS.try_import(raise_if_error=True)
53-
frompyarrowimportArrowTypeError# type: ignore # noqa: E402
54-
55-
_BIGNUMERIC_SUPPORT=False
56-
ifpyarrowisnotNone:# pragma: NO COVER
57-
_BIGNUMERIC_SUPPORT=True
52+
pyarrow=_versions_helpers.PYARROW_VERSIONS.try_import()
5853

5954
try:
6055
# _BaseGeometry is used to detect shapely objevys in `bq_to_arrow_array`
6156
fromshapely.geometry.baseimportBaseGeometryas_BaseGeometry# type: ignore
62-
exceptImportError:# pragma: NO COVER
57+
exceptImportError:
6358
# No shapely, use NoneType for _BaseGeometry as a placeholder.
6459
_BaseGeometry=type(None)
6560
else:
61+
# We don't have any unit test sessions that install shapely but not pandas.
6662
ifpandasisnotNone:# pragma: NO COVER
6763

6864
def_to_wkb():
@@ -309,10 +305,10 @@ def bq_to_arrow_array(series, bq_field):
309305
iffield_type_upperinschema._STRUCT_TYPES:
310306
returnpyarrow.StructArray.from_pandas(series,type=arrow_type)
311307
returnpyarrow.Array.from_pandas(series,type=arrow_type)
312-
exceptArrowTypeError:# pragma: NO COVER
308+
exceptpyarrow.ArrowTypeError:
313309
msg=f"""Error converting Pandas column with name: "{series.name}" and datatype: "{series.dtype}" to an appropriate pyarrow datatype: Array, ListArray, or StructArray"""
314310
_LOGGER.error(msg)
315-
raiseArrowTypeError(msg)
311+
raisepyarrow.ArrowTypeError(msg)
316312

317313

318314
defget_column_or_index(dataframe,name):

‎google/cloud/bigquery/_pyarrow_helpers.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
try:
2222
importpyarrow# type: ignore
23-
exceptImportError:# pragma: NO COVER
23+
exceptImportError:
2424
pyarrow=None
2525

2626

@@ -49,7 +49,7 @@ def pyarrow_timestamp():
4949
_BQ_TO_ARROW_SCALARS= {}
5050
_ARROW_SCALAR_IDS_TO_BQ= {}
5151

52-
ifpyarrow:# pragma: NO COVER
52+
ifpyarrow:
5353
# This dictionary is duplicated in bigquery_storage/test/unite/test_reader.py
5454
# When modifying it be sure to update it there as well.
5555
# Note(todo!!): type "BIGNUMERIC"'s matching pyarrow type is added in _pandas_helpers.py

‎google/cloud/bigquery/_tqdm_helpers.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
try:
2525
importtqdm# type: ignore
26-
importtqdm.notebookasnotebook# type: ignore
27-
28-
exceptImportError:# pragma: NO COVER
26+
exceptImportError:
2927
tqdm=None
3028

29+
try:
30+
importtqdm.notebookastqdm_notebook# type: ignore
31+
exceptImportError:
32+
tqdm_notebook=None
33+
3134
iftyping.TYPE_CHECKING:# pragma: NO COVER
3235
fromgoogle.cloud.bigqueryimportQueryJob
3336
fromgoogle.cloud.bigquery.tableimportRowIterator
@@ -42,7 +45,7 @@
4245

4346
defget_progress_bar(progress_bar_type,description,total,unit):
4447
"""Construct a tqdm progress bar object, if tqdm is installed."""
45-
iftqdmisNone:
48+
iftqdmisNoneortqdm_notebookisNoneandprogress_bar_type=="tqdm_notebook":
4649
ifprogress_bar_typeisnotNone:
4750
warnings.warn(_NO_TQDM_ERROR,UserWarning,stacklevel=3)
4851
returnNone
@@ -58,7 +61,7 @@ def get_progress_bar(progress_bar_type, description, total, unit):
5861
unit=unit,
5962
)
6063
elifprogress_bar_type=="tqdm_notebook":
61-
returnnotebook.tqdm(
64+
returntqdm_notebook.tqdm(
6265
bar_format="{l_bar}{bar}|",
6366
desc=description,
6467
file=sys.stdout,

‎google/cloud/bigquery/_versions_helpers.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def try_import(self, raise_if_error: bool = False) -> Any:
7373
"""
7474
try:
7575
importpyarrow
76-
exceptImportErrorasexc:# pragma: NO COVER
76+
exceptImportErrorasexc:
7777
ifraise_if_error:
7878
raiseexceptions.LegacyPyarrowError(
7979
"pyarrow package not found. Install pyarrow version >="
@@ -212,7 +212,7 @@ def try_import(self, raise_if_error: bool = False) -> Any:
212212
"""
213213
try:
214214
importpandas
215-
exceptImportErrorasexc:# pragma: NO COVER
215+
exceptImportErrorasexc:
216216
ifraise_if_error:
217217
raiseexceptions.LegacyPandasError(
218218
"pandas package not found. Install pandas version >="

‎google/cloud/bigquery/job/query.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@
5656

5757
try:
5858
importpandas# type: ignore
59-
exceptImportError:# pragma: NO COVER
59+
exceptImportError:
6060
pandas=None
6161

62-
try:
63-
importdb_dtypes# type: ignore
64-
exceptImportError:# pragma: NO COVER
65-
db_dtypes=None
66-
6762
iftyping.TYPE_CHECKING:# pragma: NO COVER
6863
# Assumption: type checks are only used by library developers and CI environments
6964
# that have all optional dependencies installed, thus no conditional imports.

‎google/cloud/bigquery/magics/magics.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
importIPython# type: ignore
9696
fromIPythonimportdisplay# type: ignore
9797
fromIPython.coreimportmagic_arguments# type: ignore
98-
exceptImportError:# pragma: NO COVER
98+
exceptImportError:
9999
raiseImportError("This module can only be loaded in IPython.")
100100

101101
fromgoogle.api_coreimportclient_info

‎google/cloud/bigquery/table.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
try:
2828
importpandas# type: ignore
29-
exceptImportError:# pragma: NO COVER
29+
exceptImportError:
3030
pandas=None
3131

3232
try:
3333
importpyarrow# type: ignore
34-
exceptImportError:# pragma: NO COVER
34+
exceptImportError:
3535
pyarrow=None
3636

3737
try:
3838
importdb_dtypes# type: ignore
39-
exceptImportError:# pragma: NO COVER
39+
exceptImportError:
4040
db_dtypes=None
4141

4242
try:

‎noxfile.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def default(session, install_extras=True):
8686
install_target=".[all]"
8787
else:
8888
install_target="."
89-
session.install("-e",install_target)
89+
session.install("-e",install_target,"-c",constraints_path)
9090
session.run("python","-m","pip","freeze")
9191

9292
# Run py.test against the unit tests.
@@ -115,14 +115,15 @@ def unit(session):
115115
defunit_noextras(session):
116116
"""Run the unit test suite."""
117117

118-
# Install optional dependencies that are out-of-date.
118+
# Install optional dependencies that are out-of-date to see that
119+
# we fail gracefully.
119120
# https://github.com/googleapis/python-bigquery/issues/933
120-
# There is no pyarrow 1.0.0 package for Python 3.9.
121-
121+
#
122+
# We only install this extra package on one of the two Python versions
123+
# so that it continues to be an optional dependency.
124+
# https://github.com/googleapis/python-bigquery/issues/1877
122125
ifsession.python==UNIT_TEST_PYTHON_VERSIONS[0]:
123-
session.install("pyarrow>=3.0.0")
124-
elifsession.python==UNIT_TEST_PYTHON_VERSIONS[-1]:
125-
session.install("pyarrow")
126+
session.install("pyarrow==1.0.0")
126127

127128
default(session,install_extras=False)
128129

‎samples/desktopapp/requirements-test.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ google-cloud-testutils==1.4.0
22
pytest===7.4.4; python_version == '3.7'
33
pytest==8.1.1; python_version >= '3.8'
44
mock==5.1.0
5-
pyarrow>=3.0.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
# samples/snippets should be runnable with no "extras"
12
google-cloud-testutils==1.4.0
23
pytest===7.4.4; python_version == '3.7'
34
pytest==8.1.1; python_version >= '3.8'
45
mock==5.1.0
5-
pyarrow>=3.0.0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp