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: removed pkg_resources for native namespace support #707

Merged
merged 11 commits into from
Dec 7, 2023
38 changes: 19 additions & 19 deletions pandas_gbq/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def __init__(self):
@property
def bigquery_installed_version(self):
import google.cloud.bigquery
import pkg_resources
import packaging.version

if self._bigquery_installed_version is not None:
return self._bigquery_installed_version

self._bigquery_installed_version = pkg_resources.parse_version(
self._bigquery_installed_version = packaging.version.parse(
google.cloud.bigquery.__version__
)
bigquery_minimum_version = pkg_resources.parse_version(BIGQUERY_MINIMUM_VERSION)
bigquery_minimum_version = packaging.version.parse(BIGQUERY_MINIMUM_VERSION)

if self._bigquery_installed_version < bigquery_minimum_version:
raise ImportError(
Expand All @@ -45,68 +45,68 @@ def bigquery_installed_version(self):

@property
def bigquery_has_accurate_timestamp(self):
import pkg_resources
import packaging.version

min_version = pkg_resources.parse_version(BIGQUERY_ACCURATE_TIMESTAMP_VERSION)
min_version = packaging.version.parse(BIGQUERY_ACCURATE_TIMESTAMP_VERSION)
return self.bigquery_installed_version >= min_version

@property
def bigquery_has_bignumeric(self):
import pkg_resources
import packaging.version

min_version = pkg_resources.parse_version(BIGQUERY_SUPPORTS_BIGNUMERIC_VERSION)
min_version = packaging.version.parse(BIGQUERY_SUPPORTS_BIGNUMERIC_VERSION)
return self.bigquery_installed_version >= min_version

@property
def bigquery_has_from_dataframe_with_csv(self):
import pkg_resources
import packaging.version

bigquery_from_dataframe_version = pkg_resources.parse_version(
bigquery_from_dataframe_version = packaging.version.parse(
BIGQUERY_FROM_DATAFRAME_CSV_VERSION
)
return self.bigquery_installed_version >= bigquery_from_dataframe_version

@property
def bigquery_needs_date_as_object(self):
import pkg_resources
import packaging.version

max_version = pkg_resources.parse_version(BIGQUERY_NO_DATE_AS_OBJECT_VERSION)
max_version = packaging.version.parse(BIGQUERY_NO_DATE_AS_OBJECT_VERSION)
return self.bigquery_installed_version < max_version

@property
def pandas_installed_version(self):
import pandas
import pkg_resources
import packaging.version

if self._pandas_installed_version is not None:
return self._pandas_installed_version

self._pandas_installed_version = pkg_resources.parse_version(pandas.__version__)
self._pandas_installed_version = packaging.version.parse(pandas.__version__)
return self._pandas_installed_version

@property
def pandas_has_deprecated_verbose(self):
import pkg_resources
import packaging.version

# Add check for Pandas version before showing deprecation warning.
# https://github.com/pydata/pandas-gbq/issues/157
pandas_verbosity_deprecation = pkg_resources.parse_version(
pandas_verbosity_deprecation = packaging.version.parse(
PANDAS_VERBOSITY_DEPRECATION_VERSION
)
return self.pandas_installed_version >= pandas_verbosity_deprecation

@property
def pandas_has_boolean_dtype(self):
import pkg_resources
import packaging.version

desired_version = pkg_resources.parse_version(PANDAS_BOOLEAN_DTYPE_VERSION)
desired_version = packaging.version.parse(PANDAS_BOOLEAN_DTYPE_VERSION)
return self.pandas_installed_version >= desired_version

@property
def pandas_has_parquet_with_lossless_timestamp(self):
import pkg_resources
import packaging.version

desired_version = pkg_resources.parse_version(
desired_version = packaging.version.parse(
PANDAS_PARQUET_LOSSLESS_TIMESTAMP_VERSION
)
return self.pandas_installed_version >= desired_version
Expand Down
4 changes: 2 additions & 2 deletions pandas_gbq/gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

def _test_google_api_imports():
try:
import pkg_resources # noqa
import packaging # noqa
except ImportError as ex: # pragma: NO COVER
raise ImportError("pandas-gbq requires setuptools") from ex
raise ImportError("pandas-gbq requires db-dtypes") from ex

try:
import db_dtypes # noqa
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# indefinitely. https://github.com/pydata/pandas-gbq/issues/343
"google-cloud-bigquery >=3.3.5,<4.0.0dev,!=2.4.*",
"google-cloud-bigquery-storage >=2.16.2,<3.0.0dev",
"packaging >=20.0.0",
]
extras = {
"tqdm": "tqdm>=4.23.0",
Expand All @@ -63,7 +64,7 @@
# benchmarks, etc.
packages = [
package
for package in setuptools.PEP420PackageFinder.find()
for package in setuptools.find_namespace_packages()
if package.startswith("pandas_gbq")
]

Expand Down
1 change: 1 addition & 0 deletions testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pyarrow==3.0.0
pydata-google-auth==1.5.0
tqdm==4.23.0
protobuf==3.19.5
packaging==20.0.0
8 changes: 2 additions & 6 deletions tests/system/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
import pandas.testing as tm
from pandas import DataFrame

try:
import pkg_resources # noqa
except ImportError:
raise ImportError("Could not import pkg_resources (setuptools).")
import pytest
import pytz
import pytest

from pandas_gbq import gbq
import pandas_gbq.schema


TABLE_ID = "new_test"
PANDAS_VERSION = pkg_resources.parse_version(pandas.__version__)
PANDAS_VERSION = packaging.version.parse(pandas.__version__)


def test_imports():
Expand Down