| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 13439b3 commit b1f6c9e
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,8 +12,3 @@ exclude_lines = | |||
| 12 | 12 | pragma: NO COVER | |
| 13 | 13 | # Ignore debug-only repr | |
| 14 | 14 | def __repr__ | |
| 15 | - # Ignore pkg_resources exceptions. | ||
| 16 | - # This is added at the module level as a safeguard for if someone | ||
| 17 | - # generates the code and tries to run it without pip installing. This | ||
| 18 | - # makes it virtually impossible to test properly. | ||
| 19 | - except pkg_resources.DistributionNotFound | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,7 +137,7 @@ def mypy(session): | |||
| 137 | 137 | "types-requests", | |
| 138 | 138 | "types-setuptools", | |
| 139 | 139 | ) | |
| 140 | - session.run("mypy", "google/cloud", "--show-traceback") | ||
| 140 | + session.run("mypy", "-p", "google", "--show-traceback") | ||
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | 143 | @nox.session(python=DEFAULT_PYTHON_VERSION) | |
@@ -149,7 +149,8 @@ def pytype(session): | |||
| 149 | 149 | session.install("attrs==20.3.0") | |
| 150 | 150 | session.install("-e", ".[all]") | |
| 151 | 151 | session.install(PYTYPE_VERSION) | |
| 152 | - session.run("pytype") | ||
| 152 | + # See https://github.com/google/pytype/issues/464 | ||
| 153 | + session.run("pytype", "-P", ".", "google/cloud/bigquery") | ||
| 153 | 154 | ||
| 154 | 155 | ||
| 155 | 156 | @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,7 @@ | |||
| 62 | 62 | "pandas>=1.1.0", | |
| 63 | 63 | pyarrow_dependency, | |
| 64 | 64 | "db-dtypes>=0.3.0,<2.0.0dev", | |
| 65 | + "importlib_metadata>=1.0.0; python_version<'3.8'", | ||
| 65 | 66 | ], | |
| 66 | 67 | "ipywidgets": [ | |
| 67 | 68 | "ipywidgets>=7.7.0", | |
@@ -108,16 +109,10 @@ | |||
| 108 | 109 | # benchmarks, etc. | |
| 109 | 110 | packages = [ | |
| 110 | 111 | package | |
| 111 | - for package in setuptools.PEP420PackageFinder.find() | ||
| 112 | + for package in setuptools.find_namespace_packages() | ||
| 112 | 113 | if package.startswith("google") | |
| 113 | 114 | ] | |
| 114 | 115 | ||
| 115 | - # Determine which namespaces are needed. | ||
| 116 | - namespaces = ["google"] | ||
| 117 | - if "google.cloud" in packages: | ||
| 118 | - namespaces.append("google.cloud") | ||
| 119 | - | ||
| 120 | - | ||
| 121 | 116 | setuptools.setup( | |
| 122 | 117 | name=name, | |
| 123 | 118 | version=version, | |
@@ -143,7 +138,6 @@ | |||
| 143 | 138 | ], | |
| 144 | 139 | platforms="Posix; MacOS X; Windows", | |
| 145 | 140 | packages=packages, | |
| 146 | - namespace_packages=namespaces, | ||
| 147 | 141 | install_requires=dependencies, | |
| 148 | 142 | extras_require=extras, | |
| 149 | 143 | python_requires=">=3.7", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,9 +23,13 @@ | |||
| 23 | 23 | import warnings | |
| 24 | 24 | ||
| 25 | 25 | import google.api_core.retry | |
| 26 | - import pkg_resources | ||
| 27 | 26 | import pytest | |
| 28 | 27 | ||
| 28 | + try: | ||
| 29 | + import importlib.metadata as metadata | ||
| 30 | + except ImportError: | ||
| 31 | + import importlib_metadata as metadata | ||
| 32 | + | ||
| 29 | 33 | from google.cloud import bigquery | |
| 30 | 34 | ||
| 31 | 35 | from google.cloud.bigquery import enums | |
@@ -42,11 +46,9 @@ | |||
| 42 | 46 | ) | |
| 43 | 47 | ||
| 44 | 48 | if pandas is not None: | |
| 45 | - PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version | ||
| 49 | + PANDAS_INSTALLED_VERSION = metadata.version("pandas") | ||
| 46 | 50 | else: | |
| 47 | - PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") | ||
| 48 | - | ||
| 49 | - PANDAS_INT64_VERSION = pkg_resources.parse_version("1.0.0") | ||
| 51 | + PANDAS_INSTALLED_VERSION = "0.0.0" | ||
| 50 | 52 | ||
| 51 | 53 | ||
| 52 | 54 | class MissingDataError(Exception): | |
@@ -310,10 +312,7 @@ def test_load_table_from_dataframe_w_automatic_schema(bigquery_client, dataset_i | |||
| 310 | 312 | ] | |
| 311 | 313 | ||
| 312 | 314 | ||
| 313 | - @pytest.mark.skipif( | ||
| 314 | - PANDAS_INSTALLED_VERSION < PANDAS_INT64_VERSION, | ||
| 315 | - reason="Only `pandas version >=1.0.0` is supported", | ||
| 316 | - ) | ||
| 315 | + @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") | ||
| 317 | 316 | def test_load_table_from_dataframe_w_nullable_int64_datatype( | |
| 318 | 317 | bigquery_client, dataset_id | |
| 319 | 318 | ): | |
@@ -342,7 +341,7 @@ def test_load_table_from_dataframe_w_nullable_int64_datatype( | |||
| 342 | 341 | ||
| 343 | 342 | ||
| 344 | 343 | @pytest.mark.skipif( | |
| 345 | - PANDAS_INSTALLED_VERSION < PANDAS_INT64_VERSION, | ||
| 344 | + PANDAS_INSTALLED_VERSION[0:2].startswith("0."), | ||
| 346 | 345 | reason="Only `pandas version >=1.0.0` is supported", | |
| 347 | 346 | ) | |
| 348 | 347 | def test_load_table_from_dataframe_w_nullable_int64_datatype_automatic_schema( | |
@@ -1043,9 +1042,7 @@ def test_list_rows_max_results_w_bqstorage(bigquery_client): | |||
| 1043 | 1042 | assert len(dataframe.index) == 100 | |
| 1044 | 1043 | ||
| 1045 | 1044 | ||
| 1046 | - @pytest.mark.skipif( | ||
| 1047 | - PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason="" | ||
| 1048 | - ) | ||
| 1045 | + @pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="") | ||
| 1049 | 1046 | @pytest.mark.parametrize( | |
| 1050 | 1047 | ("max_results",), | |
| 1051 | 1048 | ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,6 @@ | |||
| 17 | 17 | import json | |
| 18 | 18 | ||
| 19 | 19 | import mock | |
| 20 | - import pkg_resources | ||
| 21 | 20 | import pytest | |
| 22 | 21 | ||
| 23 | 22 | ||
@@ -45,14 +44,19 @@ | |||
| 45 | 44 | except (ImportError, AttributeError): # pragma: NO COVER | |
| 46 | 45 | tqdm = None | |
| 47 | 46 | ||
| 47 | + try: | ||
| 48 | + import importlib.metadata as metadata | ||
| 49 | + except ImportError: | ||
| 50 | + import importlib_metadata as metadata | ||
| 51 | + | ||
| 48 | 52 | from ..helpers import make_connection | |
| 49 | 53 | from .helpers import _make_client | |
| 50 | 54 | from .helpers import _make_job_resource | |
| 51 | 55 | ||
| 52 | 56 | if pandas is not None: | |
| 53 | - PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version | ||
| 57 | + PANDAS_INSTALLED_VERSION = metadata.version("pandas") | ||
| 54 | 58 | else: | |
| 55 | - PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") | ||
| 59 | + PANDAS_INSTALLED_VERSION = "0.0.0" | ||
| 56 | 60 | ||
| 57 | 61 | pandas = pytest.importorskip("pandas") | |
| 58 | 62 | ||
@@ -656,9 +660,7 @@ def test_to_dataframe_bqstorage_no_pyarrow_compression(): | |||
| 656 | 660 | ) | |
| 657 | 661 | ||
| 658 | 662 | ||
| 659 | - @pytest.mark.skipif( | ||
| 660 | - PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason="" | ||
| 661 | - ) | ||
| 663 | + @pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="") | ||
| 662 | 664 | @pytest.mark.skipif(pyarrow is None, reason="Requires `pyarrow`") | |
| 663 | 665 | def test_to_dataframe_column_dtypes(): | |
| 664 | 666 | from google.cloud.bigquery.job import QueryJob as target_class | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,11 @@ | |||
| 19 | 19 | import operator | |
| 20 | 20 | import queue | |
| 21 | 21 | import warnings | |
| 22 | - import pkg_resources | ||
| 22 | + | ||
| 23 | + try: | ||
| 24 | + import importlib.metadata as metadata | ||
| 25 | + except ImportError: | ||
| 26 | + import importlib_metadata as metadata | ||
| 23 | 27 | ||
| 24 | 28 | import mock | |
| 25 | 29 | ||
@@ -57,13 +61,10 @@ | |||
| 57 | 61 | ||
| 58 | 62 | bigquery_storage = _versions_helpers.BQ_STORAGE_VERSIONS.try_import() | |
| 59 | 63 | ||
| 60 | - PANDAS_MINIUM_VERSION = pkg_resources.parse_version("1.0.0") | ||
| 61 | - | ||
| 62 | 64 | if pandas is not None: | |
| 63 | - PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version | ||
| 65 | + PANDAS_INSTALLED_VERSION = metadata.version("pandas") | ||
| 64 | 66 | else: | |
| 65 | - # Set to less than MIN version. | ||
| 66 | - PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") | ||
| 67 | + PANDAS_INSTALLED_VERSION = "0.0.0" | ||
| 67 | 68 | ||
| 68 | 69 | ||
| 69 | 70 | skip_if_no_bignumeric = pytest.mark.skipif( | |
@@ -542,9 +543,7 @@ def test_bq_to_arrow_array_w_nullable_scalars(module_under_test, bq_type, rows): | |||
| 542 | 543 | ], | |
| 543 | 544 | ) | |
| 544 | 545 | @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") | |
| 545 | - @pytest.mark.skipif( | ||
| 546 | - PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason="" | ||
| 547 | - ) | ||
| 546 | + @pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="") | ||
| 548 | 547 | @pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`") | |
| 549 | 548 | def test_bq_to_arrow_array_w_pandas_timestamp(module_under_test, bq_type, rows): | |
| 550 | 549 | rows = [pandas.Timestamp(row) for row in rows] | |
@@ -806,10 +805,7 @@ def test_list_columns_and_indexes_with_named_index_same_as_column_name( | |||
| 806 | 805 | assert columns_and_indexes == expected | |
| 807 | 806 | ||
| 808 | 807 | ||
| 809 | - @pytest.mark.skipif( | ||
| 810 | - pandas is None or PANDAS_INSTALLED_VERSION < PANDAS_MINIUM_VERSION, | ||
| 811 | - reason="Requires `pandas version >= 1.0.0` which introduces pandas.NA", | ||
| 812 | - ) | ||
| 808 | + @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") | ||
| 813 | 809 | def test_dataframe_to_json_generator(module_under_test): | |
| 814 | 810 | utcnow = datetime.datetime.utcnow() | |
| 815 | 811 | df_data = collections.OrderedDict( | |
@@ -837,16 +833,8 @@ def test_dataframe_to_json_generator(module_under_test): | |||
| 837 | 833 | assert list(rows) == expected | |
| 838 | 834 | ||
| 839 | 835 | ||
| 836 | + @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") | ||
| 840 | 837 | def test_dataframe_to_json_generator_repeated_field(module_under_test): | |
| 841 | - pytest.importorskip( | ||
| 842 | - "pandas", | ||
| 843 | - minversion=str(PANDAS_MINIUM_VERSION), | ||
| 844 | - reason=( | ||
| 845 | - f"Requires `pandas version >= {PANDAS_MINIUM_VERSION}` " | ||
| 846 | - "which introduces pandas.NA" | ||
| 847 | - ), | ||
| 848 | - ) | ||
| 849 | - | ||
| 850 | 838 | df_data = [ | |
| 851 | 839 | collections.OrderedDict( | |
| 852 | 840 | [("repeated_col", [pandas.NA, 2, None, 4]), ("not_repeated_col", "first")] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,11 @@ | |||
| 30 | 30 | import requests | |
| 31 | 31 | import packaging | |
| 32 | 32 | import pytest | |
| 33 | - import pkg_resources | ||
| 33 | + | ||
| 34 | + try: | ||
| 35 | + import importlib.metadata as metadata | ||
| 36 | + except ImportError: | ||
| 37 | + import importlib_metadata as metadata | ||
| 34 | 38 | ||
| 35 | 39 | try: | |
| 36 | 40 | import pandas | |
@@ -76,13 +80,10 @@ | |||
| 76 | 80 | from test_utils.imports import maybe_fail_import | |
| 77 | 81 | from tests.unit.helpers import make_connection | |
| 78 | 82 | ||
| 79 | - PANDAS_MINIUM_VERSION = pkg_resources.parse_version("1.0.0") | ||
| 80 | - | ||
| 81 | 83 | if pandas is not None: | |
| 82 | - PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version | ||
| 84 | + PANDAS_INSTALLED_VERSION = metadata.version("pandas") | ||
| 83 | 85 | else: | |
| 84 | - # Set to less than MIN version. | ||
| 85 | - PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") | ||
| 86 | + PANDAS_INSTALLED_VERSION = "0.0.0" | ||
| 86 | 87 | ||
| 87 | 88 | ||
| 88 | 89 | def _make_credentials(): | |
@@ -8145,10 +8146,7 @@ def test_load_table_from_dataframe_unknown_table(self): | |||
| 8145 | 8146 | timeout=DEFAULT_TIMEOUT, | |
| 8146 | 8147 | ) | |
| 8147 | 8148 | ||
| 8148 | - @unittest.skipIf( | ||
| 8149 | - pandas is None or PANDAS_INSTALLED_VERSION < PANDAS_MINIUM_VERSION, | ||
| 8150 | - "Only `pandas version >=1.0.0` supported", | ||
| 8151 | - ) | ||
| 8149 | + @unittest.skipIf(pandas is None, "Requires `pandas`") | ||
| 8152 | 8150 | @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") | |
| 8153 | 8151 | def test_load_table_from_dataframe_w_nullable_int64_datatype(self): | |
| 8154 | 8152 | from google.cloud.bigquery.client import _DEFAULT_NUM_RETRIES | |
@@ -8193,10 +8191,7 @@ def test_load_table_from_dataframe_w_nullable_int64_datatype(self): | |||
| 8193 | 8191 | SchemaField("x", "INT64", "NULLABLE", None), | |
| 8194 | 8192 | ) | |
| 8195 | 8193 | ||
| 8196 | - @unittest.skipIf( | ||
| 8197 | - pandas is None or PANDAS_INSTALLED_VERSION < PANDAS_MINIUM_VERSION, | ||
| 8198 | - "Only `pandas version >=1.0.0` supported", | ||
| 8199 | - ) | ||
| 8194 | + @unittest.skipIf(pandas is None, "Requires `pandas`") | ||
| 8200 | 8195 | # @unittest.skipIf(pyarrow is None, "Requires `pyarrow`") | |
| 8201 | 8196 | def test_load_table_from_dataframe_w_nullable_int64_datatype_automatic_schema(self): | |
| 8202 | 8197 | from google.cloud.bigquery.client import _DEFAULT_NUM_RETRIES | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + # Copyright 2023 Google LLC | ||
| 2 | + # | ||
| 3 | + # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + # you may not use this file except in compliance with the License. | ||
| 5 | + # You may obtain a copy of the License at | ||
| 6 | + # | ||
| 7 | + # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + # | ||
| 9 | + # Unless required by applicable law or agreed to in writing, software | ||
| 10 | + # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + # See the License for the specific language governing permissions and | ||
| 13 | + # limitations under the License. | ||
| 14 | + | ||
| 15 | + import os | ||
| 16 | + import subprocess | ||
| 17 | + import sys | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + def test_namespace_package_compat(tmp_path): | ||
| 21 | + # The ``google`` namespace package should not be masked | ||
| 22 | + # by the presence of ``google-cloud-bigquery``. | ||
| 23 | + google = tmp_path / "google" | ||
| 24 | + google.mkdir() | ||
| 25 | + google.joinpath("othermod.py").write_text("") | ||
| 26 | + env = dict(os.environ, PYTHONPATH=str(tmp_path)) | ||
| 27 | + cmd = [sys.executable, "-m", "google.othermod"] | ||
| 28 | + subprocess.check_call(cmd, env=env) | ||
| 29 | + | ||
| 30 | + # The ``google.cloud`` namespace package should not be masked | ||
| 31 | + # by the presence of ``google-cloud-bigquery``. | ||
| 32 | + google_cloud = tmp_path / "google" / "cloud" | ||
| 33 | + google_cloud.mkdir() | ||
| 34 | + google_cloud.joinpath("othermod.py").write_text("") | ||
| 35 | + env = dict(os.environ, PYTHONPATH=str(tmp_path)) | ||
| 36 | + cmd = [sys.executable, "-m", "google.cloud.othermod"] | ||
| 37 | + subprocess.check_call(cmd, env=env) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments