Skip to content

Commit 406ca5d

Browse files
committed
fix: improve error messages for DataFrame registration and version handling
1 parent 911b4a2 commit 406ca5d

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

python/datafusion/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
udwf,
6767
)
6868

69-
__version__ = importlib_metadata.version(__name__)
69+
try:
70+
__version__ = importlib_metadata.version(__name__)
71+
except importlib_metadata.PackageNotFoundError:
72+
__version__ = "0.0.0"
7073

7174
__all__ = [
7275
"Accumulator",

python/datafusion/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ def register_table(self, name: str, table: Table | TableProvider) -> None:
750750
The registered table can be referenced from SQL statements executed against
751751
this context.
752752
753+
Plain :py:class:`~datafusion.dataframe.DataFrame` objects are not supported;
754+
convert them first with :meth:`datafusion.dataframe.DataFrame.into_view` or
755+
:meth:`datafusion.catalog.TableProvider.from_dataframe`.
756+
753757
Args:
754758
name: Name of the resultant table.
755759
table: DataFusion :class:`Table` or :class:`TableProvider` to add to the

python/tests/test_context.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,14 @@ def test_table_provider_from_capsule_invalid():
356356

357357
def test_register_table_with_dataframe_errors(ctx):
358358
df = ctx.from_pydict({"a": [1]})
359-
with pytest.raises(Exception): # noqa: B017
359+
with pytest.raises(Exception) as exc_info: # noqa: B017
360360
ctx.register_table("bad", df)
361361

362+
assert (
363+
str(exc_info.value)
364+
== "Expected a Table or TableProvider. Convert DataFrames with \"DataFrame.into_view()\" or \"TableProvider.from_dataframe()\"."
365+
)
366+
362367

363368
def test_register_dataset(ctx):
364369
# create a RecordBatch and register it as a pyarrow.dataset.Dataset

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl PySessionContext {
618618
py_provider.into_inner()
619619
} else {
620620
return Err(crate::errors::PyDataFusionError::Common(
621-
"Expected a Table or TableProvider.".to_string(),
621+
"Expected a Table or TableProvider. Convert DataFrames with \"DataFrame.into_view()\" or \"TableProvider.from_dataframe()\".".to_string(),
622622
));
623623
};
624624

0 commit comments

Comments
 (0)