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

fix: add missing pandas import #2116

Merged
merged 4 commits into from
Jan 27, 2024
Merged
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
15 changes: 10 additions & 5 deletions python/deltalake/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
if TYPE_CHECKING:
import os

import pandas

from deltalake._internal import DeltaDataChecker as _DeltaDataChecker
from deltalake._internal import RawDeltaTable
from deltalake._internal import create_deltalake as _create_deltalake
Expand All @@ -48,6 +46,13 @@
from deltalake.fs import DeltaStorageHandler
from deltalake.schema import Schema as DeltaSchema

try:
import pandas as pd # noqa: F811
except ModuleNotFoundError:
_has_pandas = False
else:
_has_pandas = True

MAX_SUPPORTED_READER_VERSION = 1
MAX_SUPPORTED_WRITER_VERSION = 2

Expand Down Expand Up @@ -892,7 +897,7 @@ def merge(
pyarrow.RecordBatch,
pyarrow.RecordBatchReader,
ds.Dataset,
"pandas.DataFrame",
"pd.DataFrame",
],
predicate: str,
source_alias: Optional[str] = None,
Expand Down Expand Up @@ -937,7 +942,7 @@ def merge(
source = convert_pyarrow_table(source, large_dtypes)
elif isinstance(source, ds.Dataset):
source = convert_pyarrow_dataset(source, large_dtypes)
elif isinstance(source, pandas.DataFrame):
elif _has_pandas and isinstance(source, pd.DataFrame):
source = convert_pyarrow_table(
pyarrow.Table.from_pandas(source), large_dtypes
)
Expand Down Expand Up @@ -1094,7 +1099,7 @@ def to_pandas(
columns: Optional[List[str]] = None,
filesystem: Optional[Union[str, pa_fs.FileSystem]] = None,
filters: Optional[FilterType] = None,
) -> "pandas.DataFrame":
) -> "pd.DataFrame":
"""
Build a pandas dataframe using data from the DeltaTable.

Expand Down
Loading