Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion tests/unit/test__pyarrow_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest


import numpy
pyarrow = pytest.importorskip("pyarrow", minversion="3.0.0")


Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_dbapi__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_empty_iterable(self):
self.assertEqual(list(result), [])

def test_non_empty_iterable(self):
import numpy
pytest.importorskip("pyarrow")
from tests.unit.helpers import _to_pyarrow

Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2416,13 +2416,16 @@ def test_to_arrow_error_if_pyarrow_is_none(self):
row_iterator.to_arrow()

def test_to_arrow(self):
import numpy
pyarrow = pytest.importorskip("pyarrow")
row_iterator = self._make_one()
tbl = row_iterator.to_arrow()
self.assertIsInstance(tbl, pyarrow.Table)
self.assertEqual(tbl.num_rows, 0)

def test_to_arrow_iterable(self):
import numpy
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3096,6 +3099,7 @@ def test_to_arrow_iterable_w_bqstorage(self):
bqstorage_client._transport.grpc_channel.close.assert_not_called()

def test_to_arrow(self):
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3180,6 +3184,7 @@ def test_to_arrow(self):
)

def test_to_arrow_w_nulls(self):
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3216,6 +3221,7 @@ def test_to_arrow_w_nulls(self):
self.assertEqual(ages, [32, 29, None, 111])

def test_to_arrow_w_unknown_type(self):
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3261,6 +3267,7 @@ def test_to_arrow_w_unknown_type(self):
self.assertTrue(all("sport" in str(warning) for warning in warned))

def test_to_arrow_w_empty_table(self):
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3302,6 +3309,7 @@ def test_to_arrow_w_empty_table(self):
self.assertEqual(child_field.type.value_type[1].name, "age")

def test_to_arrow_max_results_w_explicit_bqstorage_client_warning(self):
import numpy
pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery.schema import SchemaField
Expand Down Expand Up @@ -3344,6 +3352,7 @@ def test_to_arrow_max_results_w_explicit_bqstorage_client_warning(self):
mock_client._ensure_bqstorage_client.assert_not_called()

def test_to_arrow_max_results_w_create_bqstorage_client_no_warning(self):
import numpy
pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery.schema import SchemaField
Expand Down Expand Up @@ -3382,6 +3391,7 @@ def test_to_arrow_max_results_w_create_bqstorage_client_no_warning(self):
mock_client._ensure_bqstorage_client.assert_not_called()

def test_to_arrow_w_bqstorage(self):
import numpy
pyarrow = pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -3465,6 +3475,7 @@ def test_to_arrow_w_bqstorage(self):
bqstorage_client._transport.grpc_channel.close.assert_not_called()

def test_to_arrow_w_bqstorage_creates_client(self):
import numpy
pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -3498,6 +3509,7 @@ def test_to_arrow_w_bqstorage_creates_client(self):
bqstorage_client._transport.grpc_channel.close.assert_called_once()

def test_to_arrow_ensure_bqstorage_client_wo_bqstorage(self):
import numpy
pyarrow = pytest.importorskip(
"pyarrow", minversion=self.PYARROW_MINIMUM_VERSION
)
Expand Down Expand Up @@ -3531,6 +3543,7 @@ def mock_verify_version(raise_if_error: bool = False):
self.assertEqual(tbl.num_rows, 2)

def test_to_arrow_w_bqstorage_no_streams(self):
import numpy
pyarrow = pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -3570,6 +3583,7 @@ def test_to_arrow_w_bqstorage_no_streams(self):
self.assertEqual(actual_table.schema[2].name, "colB")

def test_to_arrow_progress_bar(self):
import numpy
pytest.importorskip("pyarrow")
pytest.importorskip("tqdm")
pytest.importorskip("tqdm.notebook")
Expand Down Expand Up @@ -3703,6 +3717,7 @@ def test_to_dataframe_iterable_with_dtypes(self):
self.assertEqual(df_2["age"][0], 33)

def test_to_dataframe_iterable_w_bqstorage(self):
import numpy
pandas = pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
pytest.importorskip("google.cloud.bigquery_storage")
Expand Down Expand Up @@ -3777,6 +3792,7 @@ def test_to_dataframe_iterable_w_bqstorage(self):
bqstorage_client._transport.grpc_channel.close.assert_not_called()

def test_to_dataframe_iterable_w_bqstorage_max_results_warning(self):
import numpy
pandas = pytest.importorskip("pandas")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -4804,6 +4820,7 @@ def test_to_dataframe_max_results_w_create_bqstorage_client_no_warning(self):
mock_client._ensure_bqstorage_client.assert_not_called()

def test_to_dataframe_w_bqstorage_creates_client(self):
import numpy
pytest.importorskip("pandas")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -4837,6 +4854,7 @@ def test_to_dataframe_w_bqstorage_creates_client(self):
bqstorage_client._transport.grpc_channel.close.assert_called_once()

def test_to_dataframe_w_bqstorage_no_streams(self):
import numpy
pytest.importorskip("pandas")
pytest.importorskip("google.cloud.bigquery_storage")
from google.cloud.bigquery import schema
Expand Down Expand Up @@ -4865,6 +4883,7 @@ def test_to_dataframe_w_bqstorage_no_streams(self):
self.assertTrue(got.empty)

def test_to_dataframe_w_bqstorage_logs_session(self):
import numpy
pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pytest.importorskip("pyarrow")
Expand All @@ -4889,6 +4908,7 @@ def test_to_dataframe_w_bqstorage_logs_session(self):
)

def test_to_dataframe_w_bqstorage_empty_streams(self):
import numpy
pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -4943,6 +4963,7 @@ def test_to_dataframe_w_bqstorage_empty_streams(self):
self.assertTrue(got.empty)

def test_to_dataframe_w_bqstorage_nonempty(self):
import numpy
pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -5025,6 +5046,7 @@ def test_to_dataframe_w_bqstorage_nonempty(self):
bqstorage_client._transport.grpc_channel.close.assert_not_called()

def test_to_dataframe_w_bqstorage_multiple_streams_return_unique_index(self):
import numpy
bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -5077,6 +5099,7 @@ def test_to_dataframe_w_bqstorage_multiple_streams_return_unique_index(self):
self.assertTrue(got.index.is_unique)

def test_to_dataframe_w_bqstorage_updates_progress_bar(self):
import numpy
bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -5154,6 +5177,7 @@ def blocking_to_arrow(*args, **kwargs):
tqdm_mock().close.assert_called_once()

def test_to_dataframe_w_bqstorage_exits_on_keyboardinterrupt(self):
import numpy
bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage")
pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -5329,6 +5353,7 @@ def test_to_dataframe_w_bqstorage_snapshot(self):
row_iterator.to_dataframe(bqstorage_client)

def test_to_dataframe_concat_categorical_dtype_w_pyarrow(self):
import numpy
pytest.importorskip("google.cloud.bigquery_storage")
pandas = pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_table_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import google.cloud.bigquery.table


import numpy
pyarrow = pytest.importorskip("pyarrow", minversion="3.0.0")


Expand Down