Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce compatibility with native namespace packages #706

Merged
merged 10 commits into from
Dec 1, 2023
24 changes: 0 additions & 24 deletions google/__init__.py

This file was deleted.

24 changes: 0 additions & 24 deletions google/cloud/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
]
extras = {
"pandas": ["pandas>=0.21.1"],
"pandas": ["pandas>=0.21.1", "importlib_metadata>=1.0.0; python_version<'3.8'"],
"fastavro": ["fastavro>=0.21.2"],
"pyarrow": ["pyarrow>=0.15.0"],
}
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess
import sys


def test_namespace_package_compat(tmp_path):
# The ``google`` namespace package should not be masked
# by the presence of ``google-cloud-bigquery-storage``.
google = tmp_path / "google"
google.mkdir()
google.joinpath("othermod.py").write_text("")
env = dict(os.environ, PYTHONPATH=str(tmp_path))
cmd = [sys.executable, "-m", "google.othermod"]
subprocess.check_call(cmd, env=env, shell=True)

# The ``google.cloud`` namespace package should not be masked
# by the presence of ``google-cloud-bigquery-storage``.
google_cloud = tmp_path / "google" / "cloud"
google_cloud.mkdir()
google_cloud.joinpath("othermod.py").write_text("")
env = dict(os.environ, PYTHONPATH=str(tmp_path))
cmd = [sys.executable, "-m", "google.cloud.othermod"]
subprocess.check_call(cmd, env=env, shell=True)
20 changes: 10 additions & 10 deletions tests/unit/test_reader_v1_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import pandas
import pandas.testing
import pytest
import pkg_resources

try:
import importlib.metadata as metadata
except ImportError:
import importlib_metadata as metadata

import google.api_core.exceptions
from google.cloud.bigquery_storage import types
Expand All @@ -30,9 +34,9 @@
pyarrow = pytest.importorskip("pyarrow")

if pandas is not None: # pragma: NO COVER
PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version
else: # pragma: NO COVER
PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0")
PANDAS_INSTALLED_VERSION = metadata.version("pandas")
else:
PANDAS_INSTALLED_VERSION = "0.0.0"


# This dictionary is duplicated in bigquery/google/cloud/bigquery/_pandas_helpers.py
Expand Down Expand Up @@ -178,9 +182,7 @@ def test_to_arrow_w_scalars_arrow(class_under_test, mock_gapic_client):
assert actual_table == expected_table


@pytest.mark.skipif(
PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason=""
)
@pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="")
def test_to_dataframe_w_scalars_arrow(class_under_test, mock_gapic_client):
arrow_schema = _bq_to_arrow_schema(SCALAR_COLUMNS)
arrow_batches = _bq_to_arrow_batches(SCALAR_BLOCKS, arrow_schema)
Expand Down Expand Up @@ -248,9 +250,7 @@ def test_to_dataframe_w_dtypes_arrow(class_under_test, mock_gapic_client):
)


@pytest.mark.skipif(
PANDAS_INSTALLED_VERSION >= pkg_resources.parse_version("2.0.0"), reason=""
)
@pytest.mark.skipif(PANDAS_INSTALLED_VERSION[0:2] not in ["0.", "1."], reason="")
def test_to_dataframe_empty_w_scalars_arrow(class_under_test, mock_gapic_client):
arrow_schema = _bq_to_arrow_schema(SCALAR_COLUMNS)
read_session = _generate_arrow_read_session(arrow_schema)
Expand Down