Skip to content

Commit 231ed2b

Browse files
authored
Enable doc tests in local and CI testing (#1409)
* Turn on doctests * Fix existing doc examples * Remove stale referenece to rust-toolchain removed in #1383, surpised pre-commit didn't flag for anyone else
1 parent 7b630ee commit 231ed2b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions/cache@v5
6363
with:
6464
path: ~/.cargo
65-
key: cargo-cache-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('Cargo.lock') }}
65+
key: cargo-cache-${{ matrix.toolchain }}-${{ hashFiles('Cargo.lock') }}
6666

6767
- name: Install dependencies
6868
uses: astral-sh/setup-uv@v7
@@ -106,7 +106,7 @@ jobs:
106106
RUST_BACKTRACE: 1
107107
run: |
108108
git submodule update --init
109-
uv run --no-project pytest -v . --import-mode=importlib
109+
uv run --no-project pytest -v --import-mode=importlib
110110
111111
- name: FFI unit tests
112112
run: |

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ features = ["substrait"]
7070
[tool.pytest.ini_options]
7171
asyncio_mode = "auto"
7272
asyncio_default_fixture_loop_scope = "function"
73+
addopts = "--doctest-modules"
74+
doctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"]
75+
testpaths = ["python/tests", "python/datafusion"]
7376

7477
# Enable docstring linting using the google style guide
7578
[tool.ruff.lint]

python/datafusion/dataframe.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,9 @@ def into_view(self, temporary: bool = False) -> Table:
327327
>>> df = ctx.sql("SELECT 1 AS value")
328328
>>> view = df.into_view()
329329
>>> ctx.register_table("values_view", view)
330-
>>> df.collect() # The DataFrame is still usable
331-
>>> ctx.sql("SELECT value FROM values_view").collect()
330+
>>> result = ctx.sql("SELECT value FROM values_view").collect()
331+
>>> result[0].column("value").to_pylist()
332+
[1]
332333
"""
333334
from datafusion.catalog import Table as _Table
334335

@@ -1389,9 +1390,12 @@ def fill_null(self, value: Any, subset: list[str] | None = None) -> DataFrame:
13891390
DataFrame with null values replaced where type casting is possible
13901391
13911392
Examples:
1392-
>>> df = df.fill_null(0) # Fill all nulls with 0 where possible
1393-
>>> # Fill nulls in specific string columns
1394-
>>> df = df.fill_null("missing", subset=["name", "category"])
1393+
>>> from datafusion import SessionContext, col
1394+
>>> ctx = SessionContext()
1395+
>>> df = ctx.from_pydict({"a": [1, None, 3], "b": [None, 5, 6]})
1396+
>>> filled = df.fill_null(0)
1397+
>>> filled.sort(col("a")).collect()[0].column("a").to_pylist()
1398+
[0, 1, 3]
13951399
13961400
Notes:
13971401
- Only fills nulls in columns where the value can be cast to the column type

0 commit comments

Comments
 (0)