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

refactor(python): streamline lazy imports #5302

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions py-polars/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ extend-exclude =
# Automatically generated test artifacts
venv/,
target/,

per-file-ignores =
polars/datatypes.py: B019
6 changes: 5 additions & 1 deletion py-polars/docs/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
hypothesis==6.55.0
numpy
pandas
pyarrow

hypothesis==6.56.3

ghp-import==2.1.0
sphinx==5.2.2
Expand Down
18 changes: 5 additions & 13 deletions py-polars/polars/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
from typing import TYPE_CHECKING, Any, Mapping, Sequence, overload

from polars.datatypes import Schema
from polars.import_check import (
_NUMPY_AVAILABLE,
_PANDAS_AVAILABLE,
_PYARROW_AVAILABLE,
pandas_mod,
pyarrow_mod,
)
from polars.dependencies import _NUMPY_AVAILABLE, _PANDAS_AVAILABLE, _PYARROW_AVAILABLE
from polars.dependencies import numpy as np
from polars.dependencies import pandas as pd
from polars.dependencies import pyarrow as pa
from polars.internals import DataFrame, Series

if TYPE_CHECKING:
import numpy as np
import pandas as pd
import pyarrow as pa

from polars.internals.type_aliases import Orientation


Expand Down Expand Up @@ -301,7 +294,7 @@ def from_arrow(
"""
if not _PYARROW_AVAILABLE:
raise ImportError("'pyarrow' is required when using from_arrow().")
pa = pyarrow_mod()

if isinstance(a, pa.Table):
return DataFrame._from_arrow(a, rechunk=rechunk)
elif isinstance(a, (pa.Array, pa.ChunkedArray)):
Expand Down Expand Up @@ -392,7 +385,6 @@ def from_pandas(
if not _PANDAS_AVAILABLE:
raise ImportError("'pandas' is required when using from_pandas().")

pd = pandas_mod()
if isinstance(df, (pd.Series, pd.DatetimeIndex)):
return Series._from_pandas("", df, nan_to_none=nan_to_none)
elif isinstance(df, pd.DataFrame):
Expand Down
Loading