# When two missing case IDs counted as a match

Suppose you have an answer key and a pile of predictions to mark. You need a way to tell which prediction goes with the reference answer for each question. A case ID serves that purpose. What happens if one prediction and one reference answer are both missing their IDs?

In one of our small tests, pandas paired the two missing values and called them a match. Only case A, one of the two intended questions, could actually be identified in both files. Its prediction was wrong. We followed case IDs through several fictional examples to see how a score can acquire a match no one can justify.

A list of the questions you meant to test gives you a starting point. If each question gets one prediction, its ID should appear once in the answer key and once in the predictions. Look for missing, repeated and unexpected IDs in both files. If a question gets several tries, add the trial ID so each attempt has a name of its own. The files below are separate examples of what can happen when you read, pair and score those records.

## Two different IDs became the same number

In our Node.js example, the numbers naming two cases differed on disk. When Node read them using its usual number format for JSON, a common file format for exchanging data, it rounded them to the same value. There were still two distinct IDs within each file. The collision happened between files: the program found two apparent matches where just one pair had identical original IDs.

Writing the IDs as text preserved the digits, as did reading the original numeric digits exactly. Converting numbers to text after reading them preserved the rounded values. At that point the lost distinction was gone. [How JSON numbers travel between programs](https://www.rfc-editor.org/rfc/rfc8259#section-6) · [How ECMAScript reads JSON](https://tc39.es/ecma262/multipage/structured-data.html#sec-json.parse)

A case can disappear even before the next program opens the file. Suppose the number `42` and the text `"42"` name different cases. When we made them the names of two entries in a JSON object, JSON requires entry names to be text, so Python wrote the name `"42"` twice. Python and Node.js both kept just the last label when reading it back. Reversing the entries changed which label survived.

Writing an array with the ID inside each row preserved both cases and both types. To check an export, reopen it with the program that will score it. Match the IDs and their types to the original list. [Python’s JSON encoding and decoding behavior](https://github.com/python/cpython/blob/v3.9.6/Doc/library/json.rst#repeated-names-within-an-object)

## Two missing IDs still don’t identify a question

In the missing-ID example, each file contained an entry for case A and an entry with its ID missing. The pandas software paired A with A and the two missing values with each other. Its one-to-one merge check passed. That check tells you that each row paired just once. It can’t establish that the rows with missing IDs represent the same intended question.

Of the two intended cases, only A could be identified in both files. The prediction for A disagreed with the answer key. The result was zero agreements out of one identifiable case, with just one of the two intended cases covered. [How pandas merges rows](https://pandas.pydata.org/pandas-docs/version/3.1/reference/api/pandas.DataFrame.merge.html#pandas.DataFrame.merge)

## A single prediction supplied two apparent answers

Sometimes each ID survives storage exactly, only for a comparison to change its meaning. In DuckDB 1.4.4 we paired IDs in two tables stored in the Parquet file format. One stored IDs as exact whole numbers. The other used double precision, a number format that can round large whole numbers. In this first example every ID survived storage exactly. To compare the two types, DuckDB converted them to a common type. Two different large IDs now appeared equal.

In a second example, that kind of comparison used one prediction twice. Two predictions appeared to give three agreeing rows. Comparing the IDs as exact whole numbers found two matches and a reference case with no prediction. Counting the uses of each original prediction exposed the double counting. [DuckDB’s rules for comparing numeric types](https://duckdb.org/docs/1.4/sql/data_types/typecasting)

For text IDs, [check which IDs count as equal under your matching rule](https://sapien1.com/research/check-unicode-case-ids).

## Matching the IDs still leaves the answers to check

Take an eight-row Parquet file. In one version we exchanged the labels on two cases, so both answers were now attached to the wrong IDs. In another we simply moved whole rows, keeping their answers with them. Both changes left the same IDs, the same label totals and the same serialized footer, the file’s structural metadata. Checking the label next to each exact ID told the changes apart: two different answers after the swap, none after the reorder. [Parquet file layout](https://parquet.apache.org/docs/file-format/)

If a label points to words in a document, [check that it points to the right occurrence](https://sapien1.com/research/check-text-annotation-offsets).

With the score, save the exact versions of the answer and prediction files and the lists of intended and actually scored IDs. Keep unmatched cases and record any prediction used more than once. A reader can then see exactly which cases the score describes and which IDs are missing or ambiguous.

When a later delivery changes which records IDs point to, [check whether you can trace each reference back to its original ID](https://sapien1.com/research/check-merged-reference-ids).

## Related research

- [The same accent can rescue a match or count one prediction twice](https://sapien1.com/research/check-unicode-case-ids)
- [When a catalog brings an old record back, which link should follow it?](https://sapien1.com/research/check-merged-reference-ids)

[Files and record IDs](https://sapien1.com/research#files)
