Skip to content

fix: skip sources emptied by the eligibility filters in create_question_set - #355

Open
Sahilkumar-r wants to merge 1 commit into
forecastingresearch:mainfrom
Sahilkumar-r:fix/335-empty-source-question-set
Open

Sahilkumar-r wants to merge 1 commit into
forecastingresearch:mainfrom
Sahilkumar-r:fix/335-empty-source-question-set

Conversation

@Sahilkumar-r

Copy link
Copy Markdown

Problem

When the eligibility filters remove every question of a sampled source, question set creation crashes instead of skipping that source (#335). drop_questions_that_resolve_too_soon / drop_questions_that_resolve_too_late build their mask with dfq.apply(..., axis=1, result_type="reduce"); on an empty frame that returns a Series that drops every column, so a market source whose questions are all resolved ended up with a column-less frame and a KeyError. The if dfq.empty: continue guard in create_question_set only covered an empty input frame.

Fix

  • Both market filters return an empty frame unchanged, so the columns survive.
  • create_question_set logs a warning and skips a source that prepare_source_questions leaves empty.
  • The two test_empty_market_frame_stays_empty tests now also assert the columns are kept. New tests: an empty data-source frame keeps its columns, and a market source or a dataset source whose questions are all resolved is skipped while the others are still sampled.

Not changed

An empty question_metadata.jsonl still raises KeyError: 'english' (the third case in #335). test_empty_metadata_passes_through documents that empty metadata passes every question through, so fixing it means deciding what empty metadata should mean (drop everything vs. skip the English filter). I left that for a maintainer decision.

I saw the maintainer note on #335 that this is low priority and best done after the question retirement work (#317). drop_retired_questions is already on main, so I assumed that has landed; happy to close this if you would rather hold it.

Verification

Ran in a fresh venv outside the repo (Windows, Python 3.13, pandas 2.3.3):

  • pytest src/tests/unit/question_sampling src/tests/unit/sources/test_kalshi.py: 269 passed.
  • The new and tightened tests fail without the source change (4 failures) and pass with it.
  • ruff format --check and ruff check (0.17.1) clean on the touched directories.
  • Not run: the rest of src/tests, make lint / make test as such, anything needing GCP.

AI disclosure

Written with Claude Code (Claude Sonnet 5.5) for @Sahilkumar-r. Please review it as AI-assisted work.

🤖 Generated with Claude Code

…ion_set`

`drop_questions_that_resolve_too_soon` and `drop_questions_that_resolve_too_late` build their mask with
`dfq.apply(..., axis=1)`, which on an empty frame returns a Series that drops every column, so a
market source whose questions were all filtered out crashed with a `KeyError`. A source left empty
by `prepare_source_questions` is now skipped with a warning, and the empty-frame tests assert that
the columns survive.

closes forecastingresearch#335

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant