2424import re
2525import warnings
2626from functools import cache
27- from typing import TYPE_CHECKING , Any , Iterator , Protocol
27+ from typing import TYPE_CHECKING , Any , Protocol
2828
2929try :
3030 from warnings import deprecated # Python 3.13+
@@ -64,6 +64,13 @@ def _load_optional_module(module_name: str) -> Any | None:
6464 return None
6565
6666
67+ _AUTO_REGISTER_PYTHON_VARIABLES_DEPRECATED = (
68+ "SessionContext.auto_register_python_variables is deprecated; use "
69+ "SessionContext.set_python_table_lookup() or the "
70+ "'auto_register_python_objects' keyword argument instead."
71+ )
72+
73+
6774class ArrowStreamExportable (Protocol ):
6875 """Type hint for object exporting Arrow C Stream via Arrow PyCapsule Interface.
6976
@@ -503,7 +510,8 @@ def __init__(
503510 config : SessionConfig | None = None ,
504511 runtime : RuntimeEnvBuilder | None = None ,
505512 * ,
506- auto_register_python_objects : bool = True ,
513+ auto_register_python_objects : bool | None = None ,
514+ auto_register_python_variables : bool | None = None ,
507515 ) -> None :
508516 """Main interface for executing queries with DataFusion.
509517
@@ -517,6 +525,9 @@ def __init__(
517525 auto_register_python_objects: Automatically register referenced
518526 Python objects (such as pandas or PyArrow data) when ``sql``
519527 queries reference them by name.
528+ auto_register_python_variables: Deprecated alias for
529+ ``auto_register_python_objects``. When provided, it overrides
530+ the automatic registration behavior.
520531
521532 Example usage:
522533
@@ -532,7 +543,33 @@ def __init__(
532543 config .config_internal if config is not None else None ,
533544 runtime .config_internal if runtime is not None else None ,
534545 )
535- self ._auto_python_table_lookup = auto_register_python_objects
546+ if auto_register_python_variables is not None :
547+ warnings .warn (
548+ _AUTO_REGISTER_PYTHON_VARIABLES_DEPRECATED ,
549+ DeprecationWarning ,
550+ stacklevel = 2 ,
551+ )
552+
553+ if (
554+ auto_register_python_objects is not None
555+ and auto_register_python_variables is not None
556+ and auto_register_python_objects != auto_register_python_variables
557+ ):
558+ conflict_message = (
559+ "auto_register_python_objects and auto_register_python_variables "
560+ "were provided with conflicting values."
561+ )
562+ raise ValueError (conflict_message )
563+
564+ if auto_register_python_objects is None :
565+ if auto_register_python_variables is None :
566+ auto_python_table_lookup = True
567+ else :
568+ auto_python_table_lookup = auto_register_python_variables
569+ else :
570+ auto_python_table_lookup = auto_register_python_objects
571+
572+ self ._auto_python_table_lookup = auto_python_table_lookup
536573
537574 def __repr__ (self ) -> str :
538575 """Print a string representation of the Session Context."""
@@ -579,6 +616,25 @@ def set_python_table_lookup(self, enabled: bool = True) -> SessionContext:
579616 self ._auto_python_table_lookup = enabled
580617 return self
581618
619+ @property
620+ def auto_register_python_variables (self ) -> bool :
621+ """Deprecated alias for :py:meth:`set_python_table_lookup`."""
622+ warnings .warn (
623+ _AUTO_REGISTER_PYTHON_VARIABLES_DEPRECATED ,
624+ DeprecationWarning ,
625+ stacklevel = 2 ,
626+ )
627+ return getattr (self , "_auto_python_table_lookup" , True )
628+
629+ @auto_register_python_variables .setter
630+ def auto_register_python_variables (self , enabled : bool ) -> None :
631+ warnings .warn (
632+ _AUTO_REGISTER_PYTHON_VARIABLES_DEPRECATED ,
633+ DeprecationWarning ,
634+ stacklevel = 2 ,
635+ )
636+ self .set_python_table_lookup (enabled )
637+
582638 def register_object_store (
583639 self , schema : str , store : Any , host : str | None = None
584640 ) -> None :
0 commit comments