apache/beam · error · ValueError

Source %r is empty.

Error message

Source %r is empty.

What it means

assert_split_at_fraction_exhaustive first reads the source fully; if it yields no items the exhaustive split-fraction test cannot proceed, so it raises this ValueError. Splitting tests are meaningless over an empty source.

Solutions

  1. Verify the source yields data by calling read_from_source(source) and checking it's non-empty before the exhaustive test.
  2. Fix the start_position/stop_position arguments so the range covers at least one record (start < stop).
  3. Check the underlying test data/fixture path is correct and non-empty.
  4. Skip or guard the exhaustive test when the source is legitimately empty.

Example fix

// before
assert_split_at_fraction_exhaustive(source, 5, 5)  # empty range
// after
items = read_from_source(source, 0, 10)
assert items
assert_split_at_fraction_exhaustive(source, 0, 10)
Defensive patterns

Strategy: validation

Validate before calling

items = read_from_source(source, start_position, stop_position)
if not items:
    pytest.skip('source range is empty; skipping exhaustive split test')

Try / catch

try:
    assert_split_at_fraction_exhaustive(source, start, stop)
except ValueError as e:
    if 'is empty' in str(e):
        pytest.skip(f'source produced no items: {e}')

Prevention

When it happens

Trigger: Calling assert_split_at_fraction_exhaustive(source, start_position, stop_position) where read_from_source(source, start, stop) returns an empty list — e.g. the range [start, stop) contains no records or the underlying data is empty.

Common situations: Test fixture data file empty or not loaded; start_position >= stop_position passed explicitly; source configured with a filter/range that excludes all items; pointing the source at the wrong path in CI.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b5d6122927dd842f. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/io/source_test_utils.py:588

  Asserts that for each possible start position, a source can be split at
  every interesting fraction (halfway between two fractions that differ by at
  least one item) and the results are consistent if a split succeeds.
  Verifies multi threaded splitting as well.

  Args:
    source (~apache_beam.io.iobase.BoundedSource): the source to perform
      dynamic splitting on.
    perform_multi_threaded_test (bool): if :data:`True` performs a
      multi-threaded test, otherwise this test is skipped.

  Raises:
    ValueError: if the exhaustive splitting test fails.
  """

  expected_items = read_from_source(source, start_position, stop_position)
  if not expected_items:
    raise ValueError('Source %r is empty.' % source)

  if len(expected_items) == 1:
    raise ValueError('Source %r only reads a single item.' % source)

  all_non_trivial_fractions = []

  any_successful_fractions = False
  any_non_trivial_fractions = False

  for i in range(len(expected_items)):
    stats = SplitFractionStatistics([], [])

    assert_split_at_fraction_binary(
        source, expected_items, i, 0.0, None, 1.0, None, stats)

    if stats.successful_fractions:
      any_successful_fractions = True
    if stats.non_trivial_fractions:

View on GitHub (pinned to 12126d8942)