Skip to content

chore(delphi): install pandas-stubs to fix pyright false positives#2565

Merged
jucor merged 1 commit into
edgefrom
jc/delphi-pandas-stubs
Jun 11, 2026
Merged

chore(delphi): install pandas-stubs to fix pyright false positives#2565
jucor merged 1 commit into
edgefrom
jc/delphi-pandas-stubs

Conversation

@jucor

@jucor jucor commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

pandas 2.3 ships no py.typed marker, so pyright fell back to its bundled stubs and mistyped DataFrame.__getitem__ as ndarray, producing 55 errors in polismath/pca_kmeans_rep/repness.py alone. Installing the official pandas-stubs (from the pandas-dev org) drops that to 2 errors.

The 2 remaining errors are numpy-stubs limitations, not pandas:

  • repness.py:467np.where widens p from np.ndarray to np.ndarray | bool_, so np.sum(...) is typed bool_ (pyright #2811).
  • repness.py:541np.sqrt(Series) loses Series-ness, so .fillna() looks like an attribute error (pyright #4081).

Each is silenced with a line-scoped # pyright: ignore[reportXxx] that names the specific category and links to the upstream issue. No global rule overrides, no typeCheckingMode = "off".

What changed

  • delphi/pyproject.toml — new [dependency-groups] dev = ["pandas-stubs>=3.0.3.260530"] with an explanatory comment.
  • delphi/polismath/pca_kmeans_rep/repness.py — two single-line # pyright: ignore[...] comments + 2 explanatory lines above them. No runtime behavior change.

Why not just disable the report categories globally

The handoff doc that prompted this work (HANDOFF_PYRIGHT_PANDAS_STUBS.md) explicitly called that out as the wrong answer: reportArgumentType = "none" and friends would also kill real argument-type signal everywhere. Targeted ignores keep the rest of the codebase honest.

Test plan

  • uv run pyright polismath/pca_kmeans_rep/repness.py0 errors (was 55).
  • A deliberate int-where-Series-is-expected bug is still caught (verified with a 5-line scratch script — pyright flagged both args).
  • tests/test_repness_unit.py → 22/22 pass.
  • CI green.

Notes

  • pandas-stubs is an official endorsed-by-pandas-dev package and is what Pylance ships with by default.
  • delphi/uv.lock is not tracked in this repo (only delphi/requirements.lock, which holds prod deps via pip-compile). Dev deps live in pyproject.toml only, same convention as PR chore(delphi): standardize venv as .venv and add Pyright config #2560.
  • A blog post claims pandas is now "100% type-complete" without stubs — but pandas 2.3.3 in our venv has no py.typed marker, so PEP 561 means pyright ignores its inline annotations. Confirmed by find .venv ... -name py.typed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce Pyright false positives in the Delphi polismath code by installing pandas-stubs and adding two narrowly-scoped Pyright ignores for remaining numpy-stubs typing limitations.

Changes:

  • Add pandas-stubs as a development dependency in delphi/pyproject.toml.
  • Add two line-scoped # pyright: ignore[...] suppressions in repness.py with explanatory comments and upstream Pyright issue references.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
delphi/pyproject.toml Adds a dependency-groups dev group with pandas-stubs to improve Pyright typing for pandas.
delphi/polismath/pca_kmeans_rep/repness.py Adds two targeted Pyright ignores to silence known numpy-stubs/Pyright typing issues without affecting runtime behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread delphi/pyproject.toml Outdated
pandas 2.3 ships no `py.typed` marker, so pyright fell back to its bundled
stubs and mistyped `DataFrame.__getitem__` as `ndarray`, producing 55 errors
in `polismath/pca_kmeans_rep/repness.py` alone. Adding the official
`pandas-stubs` package (from the pandas-dev org) drops it to 2 errors.

The 2 remaining errors are numpy-stubs limitations (np.where dtype loss,
np.sqrt(Series) losing Series-ness). Each is silenced with a line-scoped
`# pyright: ignore[reportXxx]` comment that names the specific report
category and points to the upstream pyright issue.

No production code semantics changed. Verified:
- `uv run pyright polismath/pca_kmeans_rep/repness.py` → 0 errors
- A deliberate `int`-for-`Series` bug is still caught
- 22/22 tests in `tests/test_repness_unit.py` pass

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jucor jucor force-pushed the jc/delphi-pandas-stubs branch from 222553f to d27d2b3 Compare June 11, 2026 16:02
@jucor jucor merged commit d22c374 into edge Jun 11, 2026
4 checks passed
@jucor jucor deleted the jc/delphi-pandas-stubs branch June 11, 2026 16:04
@github-actions

Copy link
Copy Markdown

Delphi Coverage Report

File Stmts Miss Cover
init.py 2 0 100%
benchmarks/bench_pca.py 76 76 0%
benchmarks/bench_repness.py 81 81 0%
benchmarks/bench_update_votes.py 38 38 0%
benchmarks/benchmark_utils.py 34 34 0%
components/init.py 1 0 100%
components/config.py 165 133 19%
conversation/init.py 2 0 100%
conversation/conversation.py 1062 296 72%
conversation/manager.py 131 42 68%
database/init.py 1 0 100%
database/dynamodb.py 387 234 40%
database/postgres.py 306 206 33%
pca_kmeans_rep/init.py 5 0 100%
pca_kmeans_rep/clusters.py 257 22 91%
pca_kmeans_rep/corr.py 98 17 83%
pca_kmeans_rep/pca.py 52 16 69%
pca_kmeans_rep/repness.py 297 35 88%
regression/init.py 4 0 100%
regression/clojure_comparer.py 188 20 89%
regression/comparer.py 887 720 19%
regression/datasets.py 135 27 80%
regression/recorder.py 36 27 25%
regression/utils.py 138 94 32%
run_math_pipeline.py 261 114 56%
umap_narrative/500_generate_embedding_umap_cluster.py 210 109 48%
umap_narrative/501_calculate_comment_extremity.py 112 53 53%
umap_narrative/502_calculate_priorities.py 135 135 0%
umap_narrative/700_datamapplot_for_layer.py 502 502 0%
umap_narrative/701_static_datamapplot_for_layer.py 310 310 0%
umap_narrative/702_consensus_divisive_datamapplot.py 432 432 0%
umap_narrative/801_narrative_report_batch.py 785 785 0%
umap_narrative/802_process_batch_results.py 265 265 0%
umap_narrative/803_check_batch_status.py 175 175 0%
umap_narrative/llm_factory_constructor/init.py 2 2 0%
umap_narrative/llm_factory_constructor/model_provider.py 157 157 0%
umap_narrative/polismath_commentgraph/init.py 1 0 100%
umap_narrative/polismath_commentgraph/cli.py 270 270 0%
umap_narrative/polismath_commentgraph/core/init.py 3 3 0%
umap_narrative/polismath_commentgraph/core/clustering.py 108 108 0%
umap_narrative/polismath_commentgraph/core/embedding.py 104 104 0%
umap_narrative/polismath_commentgraph/lambda_handler.py 219 219 0%
umap_narrative/polismath_commentgraph/schemas/init.py 2 0 100%
umap_narrative/polismath_commentgraph/schemas/dynamo_models.py 160 9 94%
umap_narrative/polismath_commentgraph/tests/conftest.py 17 17 0%
umap_narrative/polismath_commentgraph/tests/test_clustering.py 74 74 0%
umap_narrative/polismath_commentgraph/tests/test_embedding.py 55 55 0%
umap_narrative/polismath_commentgraph/tests/test_storage.py 87 87 0%
umap_narrative/polismath_commentgraph/utils/init.py 3 0 100%
umap_narrative/polismath_commentgraph/utils/converter.py 283 237 16%
umap_narrative/polismath_commentgraph/utils/group_data.py 354 336 5%
umap_narrative/polismath_commentgraph/utils/storage.py 584 518 11%
umap_narrative/reset_conversation.py 159 50 69%
umap_narrative/run_pipeline.py 453 312 31%
utils/general.py 62 41 34%
Total 10727 7597 29%

jucor added a commit that referenced this pull request Jun 11, 2026
Re-records `golden_snapshot.json` for `vw` and `biodiversity` against the
top of the D10/D11/D12 stack (after PRs #2564, #2566, #2567, #2568). The
previous goldens were deleted in PR #2516 because they were stale; this
PR brings them back at the new post-stack baseline.

Sits on top of D12 (PR 11) in the spr stack.

## DEFERRED

Per Julien 2026-06-11: goldens re-records belong to the Python-vs-Python
refactor comparison phase, not the current Clojure-parity chase. This
snapshot exists as a historical reference; DO NOT re-record until we
enter that phase.

Goldens add noise during Clojure-parity work — they shift on every
parity fix and have to be re-recorded with no oracle (the Clojure blob
is the only ground truth right now). Reactivate this PR (or re-create
it) once the Python pipeline is stable and we are comparing pre-vs-post
Python refactor.

## Why these goldens reflect the current state

After PR 14a (scalar deletion) + ns-PASS fix + D10 (rep selection) + D11
(consensus selection) + D12 (comment priorities), the Python pipeline
output now includes:
- The Clojure-parity `ns` semantics (counts PASS votes).
- The new Clojure-parity rep-comment selection (D10).
- The new `{'agree': [...], 'disagree': [...]}` consensus shape (D11).
- The newly-computed `comment_priorities` dict (D12).
- The pre-existing D5/D6/D7/D8/D9/D15/K-inv fixes from the
  2026-06-09/10 stack.

These snapshot files capture the combined state. They are NOT a baseline
for the `test_regression.py` regression suite during the Clojure-parity
phase — they are reference values for the future Python-vs-Python phase.

## sklearn KMeans seeding

The recorder uses sklearn's `KMeans(random_state=42)` (the default in
`polismath/pca_kmeans_rep/kmeans.py`). This produces deterministic
output across runs without requiring exact match with Clojure's
first-k-distinct initialization. The seeding policy is unchanged from
pre-D10 — this PR just re-records against the new output values.

Future work (separate PR): decide whether to switch to first-k-distinct
seeding for tighter Clojure parity, or accept the sklearn-vs-Clojure
divergence with looser comparison tolerances.

## /goal mode

Final PR in the autonomous stacked series (PR 14a → ns-PASS → D10 → D11
→ D12 → goldens) per user request. All decisions documented in
`~/polis/D10_D11_D12_GOLDENS_DECISIONS.md` for batch review.

The stack also picks up the recent edge change `#2565`
(`chore(delphi): install pandas-stubs to fix pyright false positives`),
which was rebased under all prior commits before this golden record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

commit-id:f7185ccd
jucor added a commit that referenced this pull request Jun 11, 2026
Re-records `golden_snapshot.json` for `vw` and `biodiversity` against the
top of the D10/D11/D12 stack (after PRs #2564, #2566, #2567, #2568). The
previous goldens were deleted in PR #2516 because they were stale; this
PR brings them back at the new post-stack baseline.

Sits on top of D12 (PR 11) in the spr stack.

## DEFERRED

Per Julien 2026-06-11: goldens re-records belong to the Python-vs-Python
refactor comparison phase, not the current Clojure-parity chase. This
snapshot exists as a historical reference; DO NOT re-record until we
enter that phase.

Goldens add noise during Clojure-parity work — they shift on every
parity fix and have to be re-recorded with no oracle (the Clojure blob
is the only ground truth right now). Reactivate this PR (or re-create
it) once the Python pipeline is stable and we are comparing pre-vs-post
Python refactor.

## Why these goldens reflect the current state

After PR 14a (scalar deletion) + ns-PASS fix + D10 (rep selection) + D11
(consensus selection) + D12 (comment priorities), the Python pipeline
output now includes:
- The Clojure-parity `ns` semantics (counts PASS votes).
- The new Clojure-parity rep-comment selection (D10).
- The new `{'agree': [...], 'disagree': [...]}` consensus shape (D11).
- The newly-computed `comment_priorities` dict (D12).
- The pre-existing D5/D6/D7/D8/D9/D15/K-inv fixes from the
  2026-06-09/10 stack.

These snapshot files capture the combined state. They are NOT a baseline
for the `test_regression.py` regression suite during the Clojure-parity
phase — they are reference values for the future Python-vs-Python phase.

## sklearn KMeans seeding

The recorder uses sklearn's `KMeans(random_state=42)` (the default in
`polismath/pca_kmeans_rep/kmeans.py`). This produces deterministic
output across runs without requiring exact match with Clojure's
first-k-distinct initialization. The seeding policy is unchanged from
pre-D10 — this PR just re-records against the new output values.

Future work (separate PR): decide whether to switch to first-k-distinct
seeding for tighter Clojure parity, or accept the sklearn-vs-Clojure
divergence with looser comparison tolerances.

## /goal mode

Final PR in the autonomous stacked series (PR 14a → ns-PASS → D10 → D11
→ D12 → goldens) per user request. All decisions documented in
`~/polis/D10_D11_D12_GOLDENS_DECISIONS.md` for batch review.

The stack also picks up the recent edge change `#2565`
(`chore(delphi): install pandas-stubs to fix pyright false positives`),
which was rebased under all prior commits before this golden record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

commit-id:f7185ccd
jucor added a commit that referenced this pull request Jun 11, 2026
Re-records `golden_snapshot.json` for `vw` and `biodiversity` against the
top of the D10/D11/D12 stack (after PRs #2564, #2566, #2567, #2568). The
previous goldens were deleted in PR #2516 because they were stale; this
PR brings them back at the new post-stack baseline.

Sits on top of D12 (PR 11) in the spr stack.

## DEFERRED

Per Julien 2026-06-11: goldens re-records belong to the Python-vs-Python
refactor comparison phase, not the current Clojure-parity chase. This
snapshot exists as a historical reference; DO NOT re-record until we
enter that phase.

Goldens add noise during Clojure-parity work — they shift on every
parity fix and have to be re-recorded with no oracle (the Clojure blob
is the only ground truth right now). Reactivate this PR (or re-create
it) once the Python pipeline is stable and we are comparing pre-vs-post
Python refactor.

## Why these goldens reflect the current state

After PR 14a (scalar deletion) + ns-PASS fix + D10 (rep selection) + D11
(consensus selection) + D12 (comment priorities), the Python pipeline
output now includes:
- The Clojure-parity `ns` semantics (counts PASS votes).
- The new Clojure-parity rep-comment selection (D10).
- The new `{'agree': [...], 'disagree': [...]}` consensus shape (D11).
- The newly-computed `comment_priorities` dict (D12).
- The pre-existing D5/D6/D7/D8/D9/D15/K-inv fixes from the
  2026-06-09/10 stack.

These snapshot files capture the combined state. They are NOT a baseline
for the `test_regression.py` regression suite during the Clojure-parity
phase — they are reference values for the future Python-vs-Python phase.

## sklearn KMeans seeding

The recorder uses sklearn's `KMeans(random_state=42)` (the default in
`polismath/pca_kmeans_rep/kmeans.py`). This produces deterministic
output across runs without requiring exact match with Clojure's
first-k-distinct initialization. The seeding policy is unchanged from
pre-D10 — this PR just re-records against the new output values.

Future work (separate PR): decide whether to switch to first-k-distinct
seeding for tighter Clojure parity, or accept the sklearn-vs-Clojure
divergence with looser comparison tolerances.

## /goal mode

Final PR in the autonomous stacked series (PR 14a → ns-PASS → D10 → D11
→ D12 → goldens) per user request. All decisions documented in
`~/polis/D10_D11_D12_GOLDENS_DECISIONS.md` for batch review.

The stack also picks up the recent edge change `#2565`
(`chore(delphi): install pandas-stubs to fix pyright false positives`),
which was rebased under all prior commits before this golden record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

commit-id:f7185ccd
jucor added a commit that referenced this pull request Jun 11, 2026
Re-records `golden_snapshot.json` for `vw` and `biodiversity` against the
top of the D10/D11/D12 stack (after PRs #2564, #2566, #2567, #2568). The
previous goldens were deleted in PR #2516 because they were stale; this
PR brings them back at the new post-stack baseline.

Sits on top of D12 (PR 11) in the spr stack.

## DEFERRED

Per Julien 2026-06-11: goldens re-records belong to the Python-vs-Python
refactor comparison phase, not the current Clojure-parity chase. This
snapshot exists as a historical reference; DO NOT re-record until we
enter that phase.

Goldens add noise during Clojure-parity work — they shift on every
parity fix and have to be re-recorded with no oracle (the Clojure blob
is the only ground truth right now). Reactivate this PR (or re-create
it) once the Python pipeline is stable and we are comparing pre-vs-post
Python refactor.

## Why these goldens reflect the current state

After PR 14a (scalar deletion) + ns-PASS fix + D10 (rep selection) + D11
(consensus selection) + D12 (comment priorities), the Python pipeline
output now includes:
- The Clojure-parity `ns` semantics (counts PASS votes).
- The new Clojure-parity rep-comment selection (D10).
- The new `{'agree': [...], 'disagree': [...]}` consensus shape (D11).
- The newly-computed `comment_priorities` dict (D12).
- The pre-existing D5/D6/D7/D8/D9/D15/K-inv fixes from the
  2026-06-09/10 stack.

These snapshot files capture the combined state. They are NOT a baseline
for the `test_regression.py` regression suite during the Clojure-parity
phase — they are reference values for the future Python-vs-Python phase.

## sklearn KMeans seeding

The recorder uses sklearn's `KMeans(random_state=42)` (the default in
`polismath/pca_kmeans_rep/kmeans.py`). This produces deterministic
output across runs without requiring exact match with Clojure's
first-k-distinct initialization. The seeding policy is unchanged from
pre-D10 — this PR just re-records against the new output values.

Future work (separate PR): decide whether to switch to first-k-distinct
seeding for tighter Clojure parity, or accept the sklearn-vs-Clojure
divergence with looser comparison tolerances.

## /goal mode

Final PR in the autonomous stacked series (PR 14a → ns-PASS → D10 → D11
→ D12 → goldens) per user request. All decisions documented in
`~/polis/D10_D11_D12_GOLDENS_DECISIONS.md` for batch review.

The stack also picks up the recent edge change `#2565`
(`chore(delphi): install pandas-stubs to fix pyright false positives`),
which was rebased under all prior commits before this golden record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

commit-id:f7185ccd
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.

2 participants