@@ -1143,11 +1143,22 @@ def session_id(self) -> str:
11431143 return self .ctx .session_id ()
11441144
11451145 def session_start_time (self ) -> str :
1146- """Return the session start time as an RFC 3339 formatted string."""
1146+ """Return the session start time as an RFC 3339 formatted string.
1147+
1148+ Examples:
1149+ >>> ctx = SessionContext()
1150+ >>> start_time = ctx.session_start_time()
1151+ >>> assert "T" in start_time # RFC 3339 contains a 'T' separator
1152+ """
11471153 return self .ctx .session_start_time ()
11481154
11491155 def enable_ident_normalization (self ) -> bool :
1150- """Return whether identifier normalization (lowercasing) is enabled."""
1156+ """Return whether identifier normalization (lowercasing) is enabled.
1157+
1158+ Examples:
1159+ >>> ctx = SessionContext()
1160+ >>> assert isinstance(ctx.enable_ident_normalization(), bool)
1161+ """
11511162 return self .ctx .enable_ident_normalization ()
11521163
11531164 def parse_sql_expr (self , sql : str , schema : DFSchema ) -> Expr :
@@ -1159,6 +1170,13 @@ def parse_sql_expr(self, sql: str, schema: DFSchema) -> Expr:
11591170
11601171 Returns:
11611172 Parsed expression.
1173+
1174+ Examples:
1175+ >>> from datafusion.common import DFSchema
1176+ >>> ctx = SessionContext()
1177+ >>> schema = DFSchema.empty()
1178+ >>> expr = ctx.parse_sql_expr("1 + 2", schema)
1179+ >>> assert "Int64(1) + Int64(2)" in str(expr)
11621180 """
11631181 from datafusion .expr import Expr # noqa: PLC0415
11641182
@@ -1172,11 +1190,31 @@ def execute_logical_plan(self, plan: LogicalPlan) -> DataFrame:
11721190
11731191 Returns:
11741192 DataFrame resulting from the execution.
1193+
1194+ Examples:
1195+ >>> ctx = SessionContext()
1196+ >>> df = ctx.from_pydict({"a": [1, 2, 3]})
1197+ >>> plan = df.logical_plan()
1198+ >>> df2 = ctx.execute_logical_plan(plan)
1199+ >>> df2.collect()[0].column(0)
1200+ <pyarrow.lib.ChunkedArray object at ...>
1201+ [
1202+ [
1203+ 1,
1204+ 2,
1205+ 3
1206+ ]
1207+ ]
11751208 """
11761209 return DataFrame (self .ctx .execute_logical_plan (plan ._raw_plan ))
11771210
11781211 def refresh_catalogs (self ) -> None :
1179- """Refresh catalog metadata."""
1212+ """Refresh catalog metadata.
1213+
1214+ Examples:
1215+ >>> ctx = SessionContext()
1216+ >>> ctx.refresh_catalogs()
1217+ """
11801218 self .ctx .refresh_catalogs ()
11811219
11821220 def remove_optimizer_rule (self , name : str ) -> bool :
@@ -1187,6 +1225,11 @@ def remove_optimizer_rule(self, name: str) -> bool:
11871225
11881226 Returns:
11891227 True if a rule with the given name was found and removed.
1228+
1229+ Examples:
1230+ >>> ctx = SessionContext()
1231+ >>> ctx.remove_optimizer_rule("nonexistent_rule")
1232+ False
11901233 """
11911234 return self .ctx .remove_optimizer_rule (name )
11921235
@@ -1198,6 +1241,18 @@ def table_provider(self, name: str) -> Table:
11981241
11991242 Returns:
12001243 The table provider.
1244+
1245+ Raises:
1246+ KeyError: If the table is not found.
1247+
1248+ Examples:
1249+ >>> import pyarrow as pa
1250+ >>> ctx = SessionContext()
1251+ >>> batch = pa.RecordBatch.from_pydict({"x": [1, 2]})
1252+ >>> ctx.register_record_batches("my_table", [[batch]])
1253+ >>> tbl = ctx.table_provider("my_table")
1254+ >>> tbl.schema
1255+ x: int64
12011256 """
12021257 from datafusion .catalog import Table # noqa: PLC0415
12031258
0 commit comments