|
16 | 16 | # under the License. |
17 | 17 | import datetime as dt |
18 | 18 | import gzip |
| 19 | +import inspect |
19 | 20 | import pathlib |
| 21 | +import warnings |
20 | 22 |
|
21 | 23 | import pyarrow as pa |
22 | 24 | import pyarrow.dataset as ds |
23 | 25 | import pytest |
24 | 26 | from datafusion import ( |
25 | | - DataFrame, |
26 | 27 | EXPECTED_PROVIDER_MSG, |
| 28 | + DataFrame, |
27 | 29 | RuntimeEnvBuilder, |
28 | 30 | SessionConfig, |
29 | 31 | SessionContext, |
@@ -358,6 +360,46 @@ def test_table_provider_from_dataframe(ctx): |
358 | 360 | assert [b.to_pydict() for b in result] == [{"a": [1, 2]}] |
359 | 361 |
|
360 | 362 |
|
| 363 | +def test_table_provider_from_view_warning_origin(ctx): |
| 364 | + from datafusion.table_provider import TableProvider as WrapperTableProvider |
| 365 | + |
| 366 | + wrapper_df = ctx.from_pydict({"a": [1]}) |
| 367 | + test_path = pathlib.Path(__file__).resolve() |
| 368 | + |
| 369 | + with warnings.catch_warnings(record=True) as caught: |
| 370 | + warnings.simplefilter("always") |
| 371 | + call_lineno = inspect.currentframe().f_lineno + 1 |
| 372 | + WrapperTableProvider.from_view(wrapper_df) |
| 373 | + |
| 374 | + assert len(caught) >= 1 |
| 375 | + |
| 376 | + rust_warning = next( |
| 377 | + ( |
| 378 | + warning |
| 379 | + for warning in caught |
| 380 | + if "PyTableProvider.from_view()" in str(warning.message) |
| 381 | + ), |
| 382 | + None, |
| 383 | + ) |
| 384 | + assert rust_warning is not None |
| 385 | + assert issubclass(rust_warning.category, DeprecationWarning) |
| 386 | + assert pathlib.Path(rust_warning.filename).resolve() == test_path |
| 387 | + assert rust_warning.lineno == call_lineno |
| 388 | + |
| 389 | + py_warning = next( |
| 390 | + ( |
| 391 | + warning |
| 392 | + for warning in caught |
| 393 | + if "TableProvider.from_view is deprecated" in str(warning.message) |
| 394 | + ), |
| 395 | + None, |
| 396 | + ) |
| 397 | + assert py_warning is not None |
| 398 | + assert issubclass(py_warning.category, DeprecationWarning) |
| 399 | + assert pathlib.Path(py_warning.filename).resolve() == test_path |
| 400 | + assert py_warning.lineno == call_lineno |
| 401 | + |
| 402 | + |
361 | 403 | def test_register_table_capsule_direct(ctx): |
362 | 404 | df = ctx.from_pydict({"a": [1, 2]}) |
363 | 405 | provider = df.into_view() |
|
0 commit comments