This is an automated email from the ASF dual-hosted git repository.

timsaucer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 4a776173 feat: expose SessionContext.copied_config and 
parse_capacity_limit (#1570)
4a776173 is described below

commit 4a7761736f57376a9c769efd46a8b34e7f46b8f0
Author: Tim Saucer <[email protected]>
AuthorDate: Fri Jun 5 12:01:53 2026 -0400

    feat: expose SessionContext.copied_config and parse_capacity_limit (#1570)
    
    Adds two small additions to SessionContext that mirror upstream:
    
    - copied_config(): returns a copy of the active SessionConfig wrapped
      in the existing SessionConfig Python class. Useful when callers want
      to seed a new context from another context's settings, or inspect
      the current configuration without sharing mutable state.
    
    - parse_capacity_limit(config_name, limit): static helper that parses
      size strings like "100M", "1.5G", "512K", or "0" into a byte count.
      Useful when configuring a RuntimeEnvBuilder from human-friendly
      inputs. Wraps SessionContext::parse_capacity_limit; the deprecated
      parse_memory_limit is intentionally not exposed.
    
    Three other items from the same gap cluster (runtime_env,
    copied_table_options, the deprecated parse_memory_limit) are not
    included here. The first two would require wrapping new Rust types
    (RuntimeEnv, TableOptions) whose surface is much larger than the
    accessors themselves; the third is deprecated upstream. Those are
    filed as separate follow-up issues.
    
    Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
---
 crates/core/src/context.rs   | 14 ++++++++++++++
 python/datafusion/context.py | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/crates/core/src/context.rs b/crates/core/src/context.rs
index da0df751..ce662938 100644
--- a/crates/core/src/context.rs
+++ b/crates/core/src/context.rs
@@ -1162,6 +1162,20 @@ impl PySessionContext {
         self.ctx.session_id()
     }
 
+    /// Return a copy of the active `SessionConfig`. Mutating the returned
+    /// config does not affect this context.
+    pub fn copied_config(&self) -> PySessionConfig {
+        self.ctx.copied_config().into()
+    }
+
+    /// Parse a string like `"100M"`, `"1.5G"`, or `"512K"` into a byte count.
+    /// `"0"` is accepted and returns 0. Use this when constructing a
+    /// `RuntimeEnvBuilder` from a human-friendly size string.
+    #[staticmethod]
+    pub fn parse_capacity_limit(config_name: &str, limit: &str) -> 
PyDataFusionResult<usize> {
+        Ok(SessionContext::parse_capacity_limit(config_name, limit)?)
+    }
+
     pub fn session_start_time(&self) -> String {
         self.ctx.session_start_time().to_rfc3339()
     }
diff --git a/python/datafusion/context.py b/python/datafusion/context.py
index accb60f1..3be32066 100644
--- a/python/datafusion/context.py
+++ b/python/datafusion/context.py
@@ -1506,6 +1506,45 @@ class SessionContext:
         """
         return self.ctx.enable_ident_normalization()
 
+    def copied_config(self) -> SessionConfig:
+        """Return a copy of the active :py:class:`SessionConfig`.
+
+        Mutating the returned config does not affect this context; use
+        the result when you need a starting point for a new context or
+        want to inspect the current settings independent of further
+        changes here.
+
+        Examples:
+            >>> ctx = SessionContext(SessionConfig().with_batch_size(1024))
+            >>> isinstance(ctx.copied_config(), SessionConfig)
+            True
+        """
+        config = SessionConfig()
+        config.config_internal = self.ctx.copied_config()
+        return config
+
+    @staticmethod
+    def parse_capacity_limit(config_name: str, limit: str) -> int:
+        """Parse a size string into a byte count.
+
+        Accepts strings like ``"100M"``, ``"1.5G"``, or ``"512K"``.
+        ``"0"`` is accepted and returns 0. ``config_name`` is used purely
+        for error messages and identifies which configuration setting the
+        limit belongs to. Use this helper when constructing a
+        :py:class:`RuntimeEnvBuilder` from a human-friendly size string.
+
+        Examples:
+            >>> SessionContext.parse_capacity_limit(
+            ...     "datafusion.runtime.memory_limit", "1M"
+            ... )
+            1048576
+            >>> SessionContext.parse_capacity_limit(
+            ...     "datafusion.runtime.memory_limit", "0"
+            ... )
+            0
+        """
+        return SessionContextInternal.parse_capacity_limit(config_name, limit)
+
     def parse_sql_expr(self, sql: str, schema: DFSchema) -> Expr:
         """Parse a SQL expression string into a logical expression.
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to