3131 import pyarrow
3232 import pyarrow .types
3333except ImportError : # pragma: NO COVER
34- pyarrow = None
34+ # Mock out pyarrow when missing, because methods from pyarrow.types are
35+ # used in test parameterization.
36+ pyarrow = mock .Mock ()
3537import pytest
3638import pytz
3739
@@ -85,7 +87,7 @@ def all_(*functions):
8587 return functools .partial (do_all , functions )
8688
8789
88- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
90+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
8991def test_is_datetime ():
9092 assert is_datetime (pyarrow .timestamp ("us" , tz = None ))
9193 assert not is_datetime (pyarrow .timestamp ("ms" , tz = None ))
@@ -249,15 +251,15 @@ def test_all_():
249251 ("UNKNOWN_TYPE" , "REPEATED" , is_none ),
250252 ],
251253)
252- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
254+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
253255def test_bq_to_arrow_data_type (module_under_test , bq_type , bq_mode , is_correct_type ):
254256 field = schema .SchemaField ("ignored_name" , bq_type , mode = bq_mode )
255257 actual = module_under_test .bq_to_arrow_data_type (field )
256258 assert is_correct_type (actual )
257259
258260
259261@pytest .mark .parametrize ("bq_type" , ["RECORD" , "record" , "STRUCT" , "struct" ])
260- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
262+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
261263def test_bq_to_arrow_data_type_w_struct (module_under_test , bq_type ):
262264 fields = (
263265 schema .SchemaField ("field01" , "STRING" ),
@@ -301,7 +303,7 @@ def test_bq_to_arrow_data_type_w_struct(module_under_test, bq_type):
301303
302304
303305@pytest .mark .parametrize ("bq_type" , ["RECORD" , "record" , "STRUCT" , "struct" ])
304- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
306+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
305307def test_bq_to_arrow_data_type_w_array_struct (module_under_test , bq_type ):
306308 fields = (
307309 schema .SchemaField ("field01" , "STRING" ),
@@ -345,7 +347,7 @@ def test_bq_to_arrow_data_type_w_array_struct(module_under_test, bq_type):
345347 assert actual .value_type .equals (expected_value_type )
346348
347349
348- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
350+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
349351def test_bq_to_arrow_data_type_w_struct_unknown_subfield (module_under_test ):
350352 fields = (
351353 schema .SchemaField ("field1" , "STRING" ),
@@ -442,7 +444,7 @@ def test_bq_to_arrow_data_type_w_struct_unknown_subfield(module_under_test):
442444 ],
443445)
444446@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
445- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
447+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
446448def test_bq_to_arrow_array_w_nullable_scalars (module_under_test , bq_type , rows ):
447449 series = pandas .Series (rows , dtype = "object" )
448450 bq_field = schema .SchemaField ("field_name" , bq_type )
@@ -452,7 +454,7 @@ def test_bq_to_arrow_array_w_nullable_scalars(module_under_test, bq_type, rows):
452454
453455
454456@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
455- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
457+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
456458def test_bq_to_arrow_array_w_arrays (module_under_test ):
457459 rows = [[1 , 2 , 3 ], [], [4 , 5 , 6 ]]
458460 series = pandas .Series (rows , dtype = "object" )
@@ -464,7 +466,7 @@ def test_bq_to_arrow_array_w_arrays(module_under_test):
464466
465467@pytest .mark .parametrize ("bq_type" , ["RECORD" , "record" , "STRUCT" , "struct" ])
466468@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
467- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
469+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
468470def test_bq_to_arrow_array_w_structs (module_under_test , bq_type ):
469471 rows = [
470472 {"int_col" : 123 , "string_col" : "abc" },
@@ -486,7 +488,7 @@ def test_bq_to_arrow_array_w_structs(module_under_test, bq_type):
486488
487489
488490@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
489- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
491+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
490492def test_bq_to_arrow_array_w_special_floats (module_under_test ):
491493 bq_field = schema .SchemaField ("field_name" , "FLOAT64" )
492494 rows = [float ("-inf" ), float ("nan" ), float ("inf" ), None ]
@@ -503,7 +505,7 @@ def test_bq_to_arrow_array_w_special_floats(module_under_test):
503505 assert roundtrip [3 ] is None
504506
505507
506- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
508+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
507509def test_bq_to_arrow_schema_w_unknown_type (module_under_test ):
508510 fields = (
509511 schema .SchemaField ("field1" , "STRING" ),
@@ -729,7 +731,7 @@ def test_dataframe_to_bq_schema_dict_sequence(module_under_test):
729731
730732
731733@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
732- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
734+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
733735def test_dataframe_to_arrow_with_multiindex (module_under_test ):
734736 bq_schema = (
735737 schema .SchemaField ("str_index" , "STRING" ),
@@ -796,7 +798,7 @@ def test_dataframe_to_arrow_with_multiindex(module_under_test):
796798
797799
798800@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
799- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
801+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
800802def test_dataframe_to_arrow_with_required_fields (module_under_test ):
801803 bq_schema = (
802804 schema .SchemaField ("field01" , "STRING" , mode = "REQUIRED" ),
@@ -851,7 +853,7 @@ def test_dataframe_to_arrow_with_required_fields(module_under_test):
851853
852854
853855@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
854- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
856+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
855857def test_dataframe_to_arrow_with_unknown_type (module_under_test ):
856858 bq_schema = (
857859 schema .SchemaField ("field00" , "UNKNOWN_TYPE" ),
@@ -884,7 +886,7 @@ def test_dataframe_to_arrow_with_unknown_type(module_under_test):
884886
885887
886888@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
887- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
889+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
888890def test_dataframe_to_arrow_dict_sequence_schema (module_under_test ):
889891 dict_schema = [
890892 {"name" : "field01" , "type" : "STRING" , "mode" : "REQUIRED" },
@@ -914,7 +916,7 @@ def test_dataframe_to_parquet_without_pyarrow(module_under_test, monkeypatch):
914916
915917
916918@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
917- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
919+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
918920def test_dataframe_to_parquet_w_extra_fields (module_under_test , monkeypatch ):
919921 with pytest .raises (ValueError ) as exc_context :
920922 module_under_test .dataframe_to_parquet (
@@ -926,7 +928,7 @@ def test_dataframe_to_parquet_w_extra_fields(module_under_test, monkeypatch):
926928
927929
928930@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
929- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
931+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
930932def test_dataframe_to_parquet_w_missing_fields (module_under_test , monkeypatch ):
931933 with pytest .raises (ValueError ) as exc_context :
932934 module_under_test .dataframe_to_parquet (
@@ -938,7 +940,7 @@ def test_dataframe_to_parquet_w_missing_fields(module_under_test, monkeypatch):
938940
939941
940942@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
941- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
943+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
942944def test_dataframe_to_parquet_compression_method (module_under_test ):
943945 bq_schema = (schema .SchemaField ("field00" , "STRING" ),)
944946 dataframe = pandas .DataFrame ({"field00" : ["foo" , "bar" ]})
@@ -985,7 +987,7 @@ def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow(module_under_test):
985987
986988
987989@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
988- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
990+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
989991def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow (module_under_test ):
990992 dataframe = pandas .DataFrame (
991993 data = [
@@ -1015,7 +1017,7 @@ def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow(module_under_test):
10151017
10161018
10171019@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1018- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1020+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
10191021def test_dataframe_to_bq_schema_pyarrow_fallback_fails (module_under_test ):
10201022 dataframe = pandas .DataFrame (
10211023 data = [
@@ -1040,7 +1042,7 @@ def test_dataframe_to_bq_schema_pyarrow_fallback_fails(module_under_test):
10401042
10411043
10421044@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1043- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1045+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
10441046def test_augment_schema_type_detection_succeeds (module_under_test ):
10451047 dataframe = pandas .DataFrame (
10461048 data = [
@@ -1101,7 +1103,7 @@ def test_augment_schema_type_detection_succeeds(module_under_test):
11011103
11021104
11031105@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1104- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1106+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
11051107def test_augment_schema_type_detection_fails (module_under_test ):
11061108 dataframe = pandas .DataFrame (
11071109 data = [
@@ -1137,7 +1139,7 @@ def test_augment_schema_type_detection_fails(module_under_test):
11371139 assert "struct_field" in warning_msg and "struct_field_2" in warning_msg
11381140
11391141
1140- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1142+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
11411143def test_dataframe_to_parquet_dict_sequence_schema (module_under_test ):
11421144 dict_schema = [
11431145 {"name" : "field01" , "type" : "STRING" , "mode" : "REQUIRED" },
@@ -1166,7 +1168,7 @@ def test_dataframe_to_parquet_dict_sequence_schema(module_under_test):
11661168 assert schema_arg == expected_schema_arg
11671169
11681170
1169- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1171+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
11701172def test_download_arrow_tabledata_list_unknown_field_type (module_under_test ):
11711173 fake_page = api_core .page_iterator .Page (
11721174 parent = mock .Mock (),
@@ -1202,7 +1204,7 @@ def test_download_arrow_tabledata_list_unknown_field_type(module_under_test):
12021204 assert list (col ) == [2.2 , 22.22 , 222.222 ]
12031205
12041206
1205- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1207+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
12061208def test_download_arrow_tabledata_list_known_field_type (module_under_test ):
12071209 fake_page = api_core .page_iterator .Page (
12081210 parent = mock .Mock (),
@@ -1237,7 +1239,7 @@ def test_download_arrow_tabledata_list_known_field_type(module_under_test):
12371239 assert list (col ) == ["2.2" , "22.22" , "222.222" ]
12381240
12391241
1240- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1242+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
12411243def test_download_arrow_tabledata_list_dict_sequence_schema (module_under_test ):
12421244 fake_page = api_core .page_iterator .Page (
12431245 parent = mock .Mock (),
@@ -1265,7 +1267,7 @@ def test_download_arrow_tabledata_list_dict_sequence_schema(module_under_test):
12651267
12661268
12671269@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1268- @pytest .mark .skipif (pyarrow is None , reason = "Requires `pyarrow`" )
1270+ @pytest .mark .skipif (isinstance ( pyarrow , mock . Mock ) , reason = "Requires `pyarrow`" )
12691271def test_download_dataframe_tabledata_list_dict_sequence_schema (module_under_test ):
12701272 fake_page = api_core .page_iterator .Page (
12711273 parent = mock .Mock (),
0 commit comments