Skip to content

Import time >1s when running with pandas #525

Description

@pvicente

Describe the bug

See import time when installing openai[datalib] due to pandas load time.

Screenshot 2023-07-10 at 21 12 39

To Reproduce

Install openai and compare import time with and without [datalib] extension installed (pandas).

Code snippets

In local 4s


import time
t1 = time.perf_counter()
from openai.datalib import pandas_helper
print(time.perf_counter() - t1, pandas_helper.pandas)

t1 = time.perf_counter()
try:
    pandas_helper.assert_has_pandas()
except pandas_helper.MissingDependencyError:
    pass
print(time.perf_counter() - t1, pandas_helper.pandas)

t1 = time.perf_counter()
try:
    pandas_helper.assert_has_pandas()
except pandas_helper.MissingDependencyError:
    pass
print(time.perf_counter() - t1, pandas_helper.pandas)
4.230538249947131 <module 'pandas' from '/Users/pedrovicente/.virtualenvs/openai-python-uihn/lib/python3.10/site-packages/pandas/__init__.py'>
6.669433787465096e-07 <module 'pandas' from '/Users/pedrovicente/.virtualenvs/openai-python-uihn/lib/python3.10/site-packages/pandas/__init__.py'>
2.919696271419525e-07 <module 'pandas' from '/Users/pedrovicente/.virtualenvs/openai-python-uihn/lib/python3.10/site-packages/pandas/__init__.py'>

OS

Linux

Python version

python 3.10

Library version

openai-python v0.27.2

Activity

  1. pvicente commented on Jul 11, 2023

    @pvicente
    Author

    @hallacy Could you kindly ack this and check PR please?

  2. RobertCraigie commented on Oct 18, 2023

    @RobertCraigie
    Contributor

    This has been fixed in our upcoming v1 beta!

    We now lazy import pandas and numpy so if you have them installed, they will only actually be imported when accessed.

  3. added a commit that references this issue on Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed in v1Issues addressed by the v1 beta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions