Skip to content

Initial IMDB version - #2

Merged
claudio525 merged 27 commits into
mainfrom
emp-gmm-support
Sep 17, 2026
Merged

claudio525 merged 27 commits into
mainfrom
emp-gmm-support

Conversation

@claudio525

@claudio525 claudio525 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor
  • Review for CS25.6 ingest should be minimal (or just skip) since this is pretty much a one-time script (and completely written by AI)

@claudio525

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Claude finished @claudio525's task in 4m 35s —— View job


Claude's review

  • Read repo guidelines (no CLAUDE.md / REVIEW.md present in this repo)
  • Check existing review comments to avoid duplicates (none found)
  • Review core library code (imdb/imdb.py, imdb/schema.py)
  • Review ingest script (scripts/cs25p6_ingest.py) — kept light per the PR description
  • Review tests and config
  • Post inline comments for confirmed findings
  • Post summary

Findings: 1 medium

  • imdb/imdb.py:137 — IMDB.create() doesn't check that path doesn't already exist, despite its own docstring contract. Pointing it at an existing IMDB file lets a DuckDB CatalogException from the first CREATE TABLE escape uncaught, leaking the open connection instead of failing cleanly (see inline comment).

Everything else I looked at held up well:

  • The add_records duplicate-detection merge (rel_int_id/site_int_id/component/kind/gmm_key, including NULL gmm_key for non-GMM records) is correctly exercised by test_add_records_rejects_duplicate_of_existing_record.
  • delete_event's cascading deletes use parameterized queries throughout (no SQL injection), and id reuse after deletion (_next_ids via max()+1) is safe since sites/records tied to a deleted event are fully cascaded.
  • validate()'s FK/uniqueness/gmm_key/sigma-consistency checks look sound.
  • The 1-based period_index/freq_index → ibis array indexing offset (-1 in get_psa/get_fas) is consistent with ibis's 0-based array indexing convention over DuckDB's 1-based arrays; I couldn't execute code in this sandbox to double-check empirically, so flagging as a note rather than a finding — worth a quick manual sanity check if not already covered, since current tests only assert column names/shapes, not that a specific requested period returns the value at the correct offset.

The ingest script (scripts/cs25p6_ingest.py) wasn't deeply reviewed per the PR description (one-time, AI-authored script); nothing jumped out as broken in a light pass.

Comment thread imdb/imdb.py
@claudio525
claudio525 requested a lite review from Copilot September 15, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical ingestion reliability issues and moderate database integrity and validation issues must be addressed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds the initial DuckDB-backed IMDB library, CS25.6 ingestion tooling, tests, documentation, packaging, and CI workflows.

Changes:

  • Defines the IMDB schema and read/write API.
  • Adds tests, examples, and documentation.
  • Adds parallel ingestion and project automation.
File summaries
File Summary
tests/test_imdb.py IMDB behavior tests
tests/conftest.py Shared test database fixture
tests/__init__.py Tests package marker
scripts/cs25p6_ingest.py CS25.6 ingestion pipeline; unresolved critical failure-handling and completion-marker issues, plus moderate input and validation issues
README.md Usage and schema documentation; nit regarding pSA/FAS example arguments
pyproject.toml Packaging and tooling configuration
imdb/schema.py Schema and vocabularies; metadata-table contract and schema-version docstring need correction
imdb/imdb.py Core database API; unresolved moderate validation, uniqueness, foreign-key, component, and metadata integrity issues
imdb/__init__.py Public API export
examples/read_imdb.py Read API example
.gitignore Python ignore rules
.github/workflows/publish-PyPI.yml PyPI publishing workflow
.github/workflows/ci.yml Continuous integration workflow
Review details

Suppressed comments (6)

README.md:170

  • add_records does not accept pSA/FAS as DataFrame columns; those arrays must be passed through the pSA=/FAS= arguments. As written, this example suggests putting them in records_df, which would silently omit the spectra from the database.
db.add_records(
    records_df
)  # rel_id, site_id, component, kind, pSA, FAS, scalar IM columns

imdb/imdb.py:139

  • create serializes the caller-supplied component tuple without checking it against the fixed vocabulary in schema.COMPONENTS/README. For example, IMDB.create(..., components=("typo",)) creates a database that accepts a non-schema component. Reject unknown (and preferably duplicate) components before writing db_meta.
        frequencies = frequencies or []

imdb/imdb.py:491

  • The validator checks record foreign keys but omits site_event.site_int_id and site_event.event_int_id, even though that table has no FK constraints. An orphan site-event row can therefore make get_site_event silently drop data on its inner joins while validate() reports the database clean; include site_event in the FK checks.
        fks = {
            "rel_int_id": self.con.table("realisations").rel_int_id,
            "site_int_id": self.con.table("sites").site_int_id,
            "event_int_id": self.con.table("events").event_int_id,
        }

imdb/schema.py:1

  • The module docstring labels the schema as version 0, while SCHEMA_VERSION is "1" and is used for compatibility checks. Update the docstring so generated documentation does not report the wrong schema version.
"""DDL and fixed vocabulary for the IMDB schema, version 0.

scripts/cs25p6_ingest.py:262

  • Each context row is built from every IM row, but an input file can contain both geom and rotd50 rows for one (rel_id, site_id). Because run_pSA_logic_tree assigns every prediction component="rotd50", this produces duplicate GMM logical keys and add_records rejects the fault at line 360. Deduplicate to one context row per realisation/site before calling the GMM.
        context = pd.concat(rel_contexts, ignore_index=True)

scripts/cs25p6_ingest.py:122

  • Converting the CSV header suffixes to floats loses their original spelling, but process_fault() later reconstructs names with f"pSA_{p}". A valid header such as pSA_0.10 is normalized to 0.1 and then looked up as pSA_0.1, causing a KeyError for that fault. Preserve the original column-name mapping while still storing numeric period values.
    columns = pd.read_csv(first_rel, nrows=0).columns
    return [float(c.removeprefix("pSA_")) for c in columns if c.startswith("pSA_")]
  • Files reviewed: 11/14 changed files
  • Comments generated: 8
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/cs25p6_ingest.py
Comment thread scripts/cs25p6_ingest.py
Comment thread scripts/cs25p6_ingest.py
Comment thread imdb/imdb.py
Comment thread imdb/imdb.py
Comment thread imdb/imdb.py Outdated
Comment thread scripts/cs25p6_ingest.py
Comment thread imdb/schema.py Outdated
@joelridden
joelridden marked this pull request as ready for review September 15, 2026 21:40

@joelridden joelridden 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.

Seems pretty good to me, I would like
is_real BOOLEAN NOT NULL DEFAULT TRUE,
To be added though to the site schema as that would be beneficial for my work at least.

Comment thread imdb/imdb.py Outdated
@claudio525

Copy link
Copy Markdown
Contributor Author

Seems pretty good to me, I would like is_real BOOLEAN NOT NULL DEFAULT TRUE, To be added though to the site schema as that would be beneficial for my work at least.

Yes fair point, will add as a separate PR though, so that this version works with my already generated CS200 database.

@AndrewRidden-Harper AndrewRidden-Harper 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.

Very nice! I think this unified IMDB will be very useful

@claudio525
claudio525 merged commit 5a91653 into main Sep 17, 2026
7 checks passed
@claudio525
claudio525 deleted the emp-gmm-support branch September 17, 2026 00:14
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.

4 participants