Skip to content

Commit

Permalink
feat: removed pkg_resources for native namespace support (#707)
Browse files Browse the repository at this point in the history
* feat: removed pkg_resources for native namespace compatibility

* reformatted with black

* removed unecessary imports

* removed previous changes, used packaging dependeny

* Added packaging to test google api imports

* changed importlib to packaging in tests

* removed small error

* add minimum version to packaging dependency

* added packaging to 3.7 constraints

---------

Co-authored-by: Chalmer Lowe <[email protected]>
  • Loading branch information
kiraksi and chalmerlowe authored Dec 7, 2023
1 parent edb93cc commit eeb1959
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
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

0 comments on commit eeb1959

Please sign in to comment.