Skip to content

Utility to check for required imports and raise importerror #411

@SultanOrazbayev

Description

@SultanOrazbayev

Based on this comment #391 (comment)

There is a repeated pattern of checking for function-specific imports and providing a helpful error message on failure to import, e.g.:

try:
import sparse
except ImportError: # pragma: no cover (import)
raise ImportError("sparse is required to import from pydata sparse") from None
if not isinstance(s, sparse.SparseArray):
raise TypeError(
"from_pydata_sparse only accepts objects from the `sparse` library; "
"see https://sparse.pydata.org"
)

This issue is to study the feasibility and value-added of extracting this logic into a separate utility function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    hygieneImprove code quality and reduce maintenance overhead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions