openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
src/openai/_extras/pandas_proxy.py
30lines · modecode
| 1 | from __future__ import annotations |
| 2 | |
| 3 | from typing import TYPE_CHECKING, Any |
| 4 | from typing_extensions import ClassVar, override |
| 5 | |
| 6 | from .._utils import LazyProxy |
| 7 | from ._common import MissingDependencyError, format_instructions |
| 8 | |
| 9 | if TYPE_CHECKING: |
| 10 | import pandas as pandas |
| 11 | |
| 12 | |
| 13 | PANDAS_INSTRUCTIONS = format_instructions(library="pandas", extra="datalib") |
| 14 | |
| 15 | |
| 16 | class PandasProxy(LazyProxy[Any]): |
| 17 | should_cache: ClassVar[bool] = True |
| 18 | |
| 19 | @override |
| 20 | def __load__(self) -> Any: |
| 21 | try: |
| 22 | import pandas |
| 23 | except ImportError: |
| 24 | raise MissingDependencyError(PANDAS_INSTRUCTIONS) |
| 25 | |
| 26 | return pandas |
| 27 | |
| 28 | |
| 29 | if not TYPE_CHECKING: |
| 30 | pandas = PandasProxy() |
| 31 | |