Repository: ibis-project/ibis

Issue:
docs: interactive mode isn't persisted in some examples
### Please describe the issue

I'm looking at https://ibis-project.org/reference/expression-tables#ibis.expr.types.relations.Table.pivot_longer. The first `>>>` block is rendered in interactive mode. The rest are not, but should be.

This is caused by https://github.com/ibis-project/ibis/commit/502b88cb0c86d33b1bd6fdd0b35a6d19f283268b. I couldn't find the PR or other info on why that commit was motivated.

Should we go through these cases and turn on interactive mode before every example? This seems pretty boilerplatey. Perhaps better would be to add a `quartodoc: +INTERACTIVE` pragma or something to each docstring, similar to `quartodoc: +SKIP`? Not sure what the best semantics there should be.

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion:
Thanks for the report. Yeah, this does look it's from 502b88c.
Maybe next step is drudgery of looking throuhg docs and seeing how prevalent this is?
Nah, I think we just need to figure out what's happening with turning off interactive mode. This happens automatically as part of rendering, it's not something we need to manually alter.

Resolving patch:
diff --git a/docs/_renderer.py b/docs/_renderer.py
--- a/docs/_renderer.py
+++ b/docs/_renderer.py
@@ -28,8 +28,6 @@ def render(self, el: qd.ast.ExampleCode) -> str:
             lambda line: quartodoc_skip_doctest in line or skip_doctest in line
         )
 
-        has_executed_chunks = False
-
         for chunk in toolz.partitionby(chunker, lines):
             first, *rest = chunk
 
@@ -39,11 +37,22 @@ def render(self, el: qd.ast.ExampleCode) -> str:
                 # check whether to skip execution and if so, render the code
                 # block as `python` (not `{python}`) if it's marked with
                 # skip_doctest, expect_failure or quartodoc_skip_doctest
-                if any(map(should_skip, chunk)):
+                if skipped := any(map(should_skip, chunk)):
                     start = end = ""
                 else:
-                    has_executed_chunks = True
                     start, end = "{}"
+                    result.append(
+                        dedent(
+                            """
+                            ```{python}
+                            #| echo: false
+
+                            import ibis
+                            ibis.options.interactive = True
+                            ```
+                            """
+                        )
+                    )
 
                 result.append(f"```{start}python{end}")
 
@@ -67,22 +76,16 @@ def render(self, el: qd.ast.ExampleCode) -> str:
                 result.extend(rest)
                 result.append("```\n")
 
-        examples = "\n".join(result)
-
-        if has_executed_chunks:
-            # turn off interactive mode before rendering
-            return (
-                dedent(
-                    """
-                    ```{python}
-                    #| echo: false
-
-                    import ibis
-                    ibis.options.interactive = False
-                    ```
-                    """
-                )
-                + examples
-            )
-        else:
-            return examples
+                if not skipped:
+                    result.append(
+                        dedent(
+                            """
+                            ```{python}
+                            #| echo: false
+                            ibis.options.interactive = False
+                            ```
+                            """
+                        )
+                    )
+
+        return "\n".join(result)
diff --git a/ibis/expr/api.py b/ibis/expr/api.py
--- a/ibis/expr/api.py
+++ b/ibis/expr/api.py
@@ -326,8 +326,7 @@ def table(
     Create a table with no data backing it
 
     >>> import ibis
-    >>> ibis.options.interactive
-    False
+    >>> ibis.options.interactive = False
     >>> t = ibis.table(schema=dict(a="int", b="string"), name="t")
     >>> t
     UnboundTable: t
diff --git a/ibis/selectors.py b/ibis/selectors.py
--- a/ibis/selectors.py
+++ b/ibis/selectors.py
@@ -180,11 +180,8 @@ def numeric() -> Predicate:
     >>> import ibis
     >>> import ibis.selectors as s
     >>> t = ibis.table(dict(a="int", b="string", c="array<string>"), name="t")
-    >>> t
-    UnboundTable: t
-      a int64
-      b string
-      c array<string>
+    >>> t.columns
+    ['a', 'b', 'c']
     >>> expr = t.select(s.numeric())  # `a` has integer type, so it's numeric
     >>> expr.columns
     ['a']


Test patch: