Skip to content

Commit

Permalink
refactor(python): streamline lazy imports (#5302)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie authored Oct 24, 2022
1 parent 1ba4a58 commit e89d359
Show file tree
Hide file tree
Showing 21 changed files with 352 additions and 395 deletions.
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

0 comments on commit e89d359

Please sign in to comment.