@@ -503,7 +503,7 @@ def __init__(
503503 config : SessionConfig | None = None ,
504504 runtime : RuntimeEnvBuilder | None = None ,
505505 * ,
506- auto_register_python_objects : bool = True ,
506+ auto_register_python_objects : bool | None = None ,
507507 ) -> None :
508508 """Main interface for executing queries with DataFusion.
509509
@@ -516,7 +516,10 @@ def __init__(
516516 runtime: Runtime configuration options.
517517 auto_register_python_objects: Automatically register referenced
518518 Python objects (such as pandas or PyArrow data) when ``sql``
519- queries reference them by name.
519+ queries reference them by name. When omitted, this defaults to
520+ the value configured via
521+ :py:meth:`~datafusion.SessionConfig.with_python_table_lookup`
522+ (``False`` unless explicitly enabled).
520523
521524 Example usage:
522525
@@ -532,6 +535,12 @@ def __init__(
532535 config .config_internal if config is not None else None ,
533536 runtime .config_internal if runtime is not None else None ,
534537 )
538+
539+ if auto_register_python_objects is None :
540+ auto_register_python_objects = getattr (
541+ config , "_python_table_lookup" , False
542+ )
543+
535544 self ._auto_python_table_lookup = auto_register_python_objects
536545
537546 def __repr__ (self ) -> str :
@@ -560,18 +569,18 @@ def enable_url_table(self) -> SessionContext:
560569 obj = klass .__new__ (klass )
561570 obj .ctx = self .ctx .enable_url_table ()
562571 obj ._auto_python_table_lookup = getattr (
563- self , "_auto_python_table_lookup" , True
572+ self , "_auto_python_table_lookup" , False
564573 )
565574 return obj
566575
567576 def set_python_table_lookup (self , enabled : bool = True ) -> SessionContext :
568577 """Enable or disable automatic registration of Python objects in SQL.
569578
570579 Args:
571- enabled: When ``True`` (default) , SQL queries automatically attempt
572- to resolve missing table names by looking up Python objects in
573- the caller's scope. When ``False``, missing tables will raise an
574- error unless they have been explicitly registered .
580+ enabled: When ``True``, SQL queries automatically attempt to
581+ resolve missing table names by looking up Python objects in the
582+ caller's scope. Use ``False`` to require explicit registration
583+ of any referenced tables .
575584
576585 Returns:
577586 The current :py:class:`SessionContext` instance for chaining.
@@ -653,7 +662,7 @@ def _execute_sql() -> DataFrame:
653662 try :
654663 return _execute_sql ()
655664 except Exception as err :
656- if not getattr (self , "_auto_python_table_lookup" , True ):
665+ if not getattr (self , "_auto_python_table_lookup" , False ):
657666 raise
658667
659668 missing_tables = self ._extract_missing_table_names (err )
0 commit comments