|
31 | 31 | import pyarrow |
32 | 32 | import pyarrow.types |
33 | 33 | except 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() |
35 | 37 | import pytest |
36 | 38 | import pytz |
37 | 39 |
|
@@ -85,7 +87,7 @@ def all_(*functions): |
85 | 87 | return functools.partial(do_all, functions) |
86 | 88 |
|
87 | 89 |
|
88 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 90 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
89 | 91 | def test_is_datetime(): |
90 | 92 | assert is_datetime(pyarrow.timestamp("us", tz=None)) |
91 | 93 | assert not is_datetime(pyarrow.timestamp("ms", tz=None)) |
@@ -249,15 +251,15 @@ def test_all_(): |
249 | 251 | ("UNKNOWN_TYPE", "REPEATED", is_none), |
250 | 252 | ], |
251 | 253 | ) |
252 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 254 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
253 | 255 | def test_bq_to_arrow_data_type(module_under_test, bq_type, bq_mode, is_correct_type): |
254 | 256 | field = schema.SchemaField("ignored_name", bq_type, mode=bq_mode) |
255 | 257 | actual = module_under_test.bq_to_arrow_data_type(field) |
256 | 258 | assert is_correct_type(actual) |
257 | 259 |
|
258 | 260 |
|
259 | 261 | @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`") |
261 | 263 | def test_bq_to_arrow_data_type_w_struct(module_under_test, bq_type): |
262 | 264 | fields = ( |
263 | 265 | schema.SchemaField("field01", "STRING"), |
@@ -301,7 +303,7 @@ def test_bq_to_arrow_data_type_w_struct(module_under_test, bq_type): |
301 | 303 |
|
302 | 304 |
|
303 | 305 | @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`") |
305 | 307 | def test_bq_to_arrow_data_type_w_array_struct(module_under_test, bq_type): |
306 | 308 | fields = ( |
307 | 309 | schema.SchemaField("field01", "STRING"), |
@@ -345,7 +347,7 @@ def test_bq_to_arrow_data_type_w_array_struct(module_under_test, bq_type): |
345 | 347 | assert actual.value_type.equals(expected_value_type) |
346 | 348 |
|
347 | 349 |
|
348 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 350 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
349 | 351 | def test_bq_to_arrow_data_type_w_struct_unknown_subfield(module_under_test): |
350 | 352 | fields = ( |
351 | 353 | schema.SchemaField("field1", "STRING"), |
@@ -442,7 +444,7 @@ def test_bq_to_arrow_data_type_w_struct_unknown_subfield(module_under_test): |
442 | 444 | ], |
443 | 445 | ) |
444 | 446 | @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`") |
446 | 448 | def test_bq_to_arrow_array_w_nullable_scalars(module_under_test, bq_type, rows): |
447 | 449 | series = pandas.Series(rows, dtype="object") |
448 | 450 | 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): |
452 | 454 |
|
453 | 455 |
|
454 | 456 | @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`") |
456 | 458 | def test_bq_to_arrow_array_w_arrays(module_under_test): |
457 | 459 | rows = [[1, 2, 3], [], [4, 5, 6]] |
458 | 460 | series = pandas.Series(rows, dtype="object") |
@@ -464,7 +466,7 @@ def test_bq_to_arrow_array_w_arrays(module_under_test): |
464 | 466 |
|
465 | 467 | @pytest.mark.parametrize("bq_type", ["RECORD", "record", "STRUCT", "struct"]) |
466 | 468 | @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`") |
468 | 470 | def test_bq_to_arrow_array_w_structs(module_under_test, bq_type): |
469 | 471 | rows = [ |
470 | 472 | {"int_col": 123, "string_col": "abc"}, |
@@ -486,7 +488,7 @@ def test_bq_to_arrow_array_w_structs(module_under_test, bq_type): |
486 | 488 |
|
487 | 489 |
|
488 | 490 | @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`") |
490 | 492 | def test_bq_to_arrow_array_w_special_floats(module_under_test): |
491 | 493 | bq_field = schema.SchemaField("field_name", "FLOAT64") |
492 | 494 | rows = [float("-inf"), float("nan"), float("inf"), None] |
@@ -503,7 +505,7 @@ def test_bq_to_arrow_array_w_special_floats(module_under_test): |
503 | 505 | assert roundtrip[3] is None |
504 | 506 |
|
505 | 507 |
|
506 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 508 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
507 | 509 | def test_bq_to_arrow_schema_w_unknown_type(module_under_test): |
508 | 510 | fields = ( |
509 | 511 | schema.SchemaField("field1", "STRING"), |
@@ -729,7 +731,7 @@ def test_dataframe_to_bq_schema_dict_sequence(module_under_test): |
729 | 731 |
|
730 | 732 |
|
731 | 733 | @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`") |
733 | 735 | def test_dataframe_to_arrow_with_multiindex(module_under_test): |
734 | 736 | bq_schema = ( |
735 | 737 | schema.SchemaField("str_index", "STRING"), |
@@ -796,7 +798,7 @@ def test_dataframe_to_arrow_with_multiindex(module_under_test): |
796 | 798 |
|
797 | 799 |
|
798 | 800 | @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`") |
800 | 802 | def test_dataframe_to_arrow_with_required_fields(module_under_test): |
801 | 803 | bq_schema = ( |
802 | 804 | schema.SchemaField("field01", "STRING", mode="REQUIRED"), |
@@ -851,7 +853,7 @@ def test_dataframe_to_arrow_with_required_fields(module_under_test): |
851 | 853 |
|
852 | 854 |
|
853 | 855 | @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`") |
855 | 857 | def test_dataframe_to_arrow_with_unknown_type(module_under_test): |
856 | 858 | bq_schema = ( |
857 | 859 | schema.SchemaField("field00", "UNKNOWN_TYPE"), |
@@ -884,7 +886,7 @@ def test_dataframe_to_arrow_with_unknown_type(module_under_test): |
884 | 886 |
|
885 | 887 |
|
886 | 888 | @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`") |
888 | 890 | def test_dataframe_to_arrow_dict_sequence_schema(module_under_test): |
889 | 891 | dict_schema = [ |
890 | 892 | {"name": "field01", "type": "STRING", "mode": "REQUIRED"}, |
@@ -914,7 +916,7 @@ def test_dataframe_to_parquet_without_pyarrow(module_under_test, monkeypatch): |
914 | 916 |
|
915 | 917 |
|
916 | 918 | @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`") |
918 | 920 | def test_dataframe_to_parquet_w_extra_fields(module_under_test, monkeypatch): |
919 | 921 | with pytest.raises(ValueError) as exc_context: |
920 | 922 | module_under_test.dataframe_to_parquet( |
@@ -926,7 +928,7 @@ def test_dataframe_to_parquet_w_extra_fields(module_under_test, monkeypatch): |
926 | 928 |
|
927 | 929 |
|
928 | 930 | @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`") |
930 | 932 | def test_dataframe_to_parquet_w_missing_fields(module_under_test, monkeypatch): |
931 | 933 | with pytest.raises(ValueError) as exc_context: |
932 | 934 | module_under_test.dataframe_to_parquet( |
@@ -938,7 +940,7 @@ def test_dataframe_to_parquet_w_missing_fields(module_under_test, monkeypatch): |
938 | 940 |
|
939 | 941 |
|
940 | 942 | @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`") |
942 | 944 | def test_dataframe_to_parquet_compression_method(module_under_test): |
943 | 945 | bq_schema = (schema.SchemaField("field00", "STRING"),) |
944 | 946 | dataframe = pandas.DataFrame({"field00": ["foo", "bar"]}) |
@@ -985,7 +987,7 @@ def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow(module_under_test): |
985 | 987 |
|
986 | 988 |
|
987 | 989 | @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`") |
989 | 991 | def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow(module_under_test): |
990 | 992 | dataframe = pandas.DataFrame( |
991 | 993 | data=[ |
@@ -1015,7 +1017,7 @@ def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow(module_under_test): |
1015 | 1017 |
|
1016 | 1018 |
|
1017 | 1019 | @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`") |
1019 | 1021 | def test_dataframe_to_bq_schema_pyarrow_fallback_fails(module_under_test): |
1020 | 1022 | dataframe = pandas.DataFrame( |
1021 | 1023 | data=[ |
@@ -1040,7 +1042,7 @@ def test_dataframe_to_bq_schema_pyarrow_fallback_fails(module_under_test): |
1040 | 1042 |
|
1041 | 1043 |
|
1042 | 1044 | @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`") |
1044 | 1046 | def test_augment_schema_type_detection_succeeds(module_under_test): |
1045 | 1047 | dataframe = pandas.DataFrame( |
1046 | 1048 | data=[ |
@@ -1101,7 +1103,7 @@ def test_augment_schema_type_detection_succeeds(module_under_test): |
1101 | 1103 |
|
1102 | 1104 |
|
1103 | 1105 | @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`") |
1105 | 1107 | def test_augment_schema_type_detection_fails(module_under_test): |
1106 | 1108 | dataframe = pandas.DataFrame( |
1107 | 1109 | data=[ |
@@ -1137,7 +1139,7 @@ def test_augment_schema_type_detection_fails(module_under_test): |
1137 | 1139 | assert "struct_field" in warning_msg and "struct_field_2" in warning_msg |
1138 | 1140 |
|
1139 | 1141 |
|
1140 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 1142 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
1141 | 1143 | def test_dataframe_to_parquet_dict_sequence_schema(module_under_test): |
1142 | 1144 | dict_schema = [ |
1143 | 1145 | {"name": "field01", "type": "STRING", "mode": "REQUIRED"}, |
@@ -1166,7 +1168,7 @@ def test_dataframe_to_parquet_dict_sequence_schema(module_under_test): |
1166 | 1168 | assert schema_arg == expected_schema_arg |
1167 | 1169 |
|
1168 | 1170 |
|
1169 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 1171 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
1170 | 1172 | def test_download_arrow_tabledata_list_unknown_field_type(module_under_test): |
1171 | 1173 | fake_page = api_core.page_iterator.Page( |
1172 | 1174 | parent=mock.Mock(), |
@@ -1202,7 +1204,7 @@ def test_download_arrow_tabledata_list_unknown_field_type(module_under_test): |
1202 | 1204 | assert list(col) == [2.2, 22.22, 222.222] |
1203 | 1205 |
|
1204 | 1206 |
|
1205 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 1207 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
1206 | 1208 | def test_download_arrow_tabledata_list_known_field_type(module_under_test): |
1207 | 1209 | fake_page = api_core.page_iterator.Page( |
1208 | 1210 | parent=mock.Mock(), |
@@ -1237,7 +1239,7 @@ def test_download_arrow_tabledata_list_known_field_type(module_under_test): |
1237 | 1239 | assert list(col) == ["2.2", "22.22", "222.222"] |
1238 | 1240 |
|
1239 | 1241 |
|
1240 | | -@pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") |
| 1242 | +@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") |
1241 | 1243 | def test_download_arrow_tabledata_list_dict_sequence_schema(module_under_test): |
1242 | 1244 | fake_page = api_core.page_iterator.Page( |
1243 | 1245 | parent=mock.Mock(), |
@@ -1265,7 +1267,7 @@ def test_download_arrow_tabledata_list_dict_sequence_schema(module_under_test): |
1265 | 1267 |
|
1266 | 1268 |
|
1267 | 1269 | @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`") |
1269 | 1271 | def test_download_dataframe_tabledata_list_dict_sequence_schema(module_under_test): |
1270 | 1272 | fake_page = api_core.page_iterator.Page( |
1271 | 1273 | parent=mock.Mock(), |
|