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

MAINT: Use importlib.metadata and packaging instead of deprecated pkg_resources #3133

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import random
import hashlib
import warnings
from importlib.metadata import version as importlib_version
from importlib.metadata import PackageNotFoundError
from typing import Union, MutableMapping, Optional, Dict, Sequence, TYPE_CHECKING, List
from types import ModuleType

import pandas as pd
from toolz import curried
from typing import TypeVar
from packaging.version import Version

from .core import sanitize_dataframe, sanitize_arrow_table, _DataFrameLike
from .core import sanitize_geo_interface
Expand Down Expand Up @@ -349,25 +352,23 @@ def curry(*args, **kwargs):


def import_pyarrow_interchange() -> ModuleType:
import pkg_resources

try:
pkg_resources.require("pyarrow>=11.0.0")
# The package is installed and meets the minimum version requirement
import pyarrow.interchange as pi

return pi
except pkg_resources.DistributionNotFound as err:
# The package is not installed
raise ImportError(
"Usage of the DataFrame Interchange Protocol requires the package 'pyarrow', but it is not installed."
) from err
except pkg_resources.VersionConflict as err:
# The package is installed but does not meet the minimum version requirement
pyarrow_version_str = importlib_version("pyarrow")
except PackageNotFoundError as err:
raise ImportError(
"The installed version of 'pyarrow' does not meet the minimum requirement of version 11.0.0. "
"Please update 'pyarrow' to use the DataFrame Interchange Protocol."
"Usage of the DataFrame Interchange Protocol requires the package"
+ " 'pyarrow', but it is not installed."
) from err
else:
if Version(pyarrow_version_str) < Version("11.0.0"):
raise ImportError(
"The installed version of 'pyarrow' does not meet the minimum requirement of version 11.0.0. "
"Please update 'pyarrow' to use the DataFrame Interchange Protocol."
)
else:
import pyarrow.interchange as pi

return pi


def pyarrow_available() -> bool:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies = [
"jsonschema>=3.0",
"numpy",
"pandas>=0.18",
"toolz"
"toolz",
"packaging"
]
description = "Vega-Altair: A declarative statistical visualization library for Python."
readme = "README.md"
Expand Down