@@ -180,3 +180,94 @@ def test_mismatched_media_is_rejected():
180180
181181 with pytest .raises (ValueError ):
182182 corpus .media = ["only one" ]
183+
184+
185+ def test_every_row_is_its_own_document_by_default ():
186+ """1.0 fits on whole documents, so the grouping key is the identity."""
187+ corpus = Corpus (documents = ["first" , "second" , "third" ])
188+
189+ assert list (corpus .document_ids ) == [0 , 1 , 2 ]
190+ assert corpus .nr_documents == len (corpus )
191+
192+
193+ def test_rows_may_share_a_document ():
194+ """What a sentence splitter would produce: four rows from two documents.
195+
196+ Nothing generates this in 1.0. The key exists so that 1.1 can add a splitter without
197+ a second pass over the data layer.
198+ """
199+ corpus = Corpus (
200+ documents = ["first half" , "second half" , "another one" , "and its tail" ],
201+ document_ids = np .array ([0 , 0 , 1 , 1 ]),
202+ )
203+
204+ assert corpus .nr_documents == 2
205+ assert len (corpus ) == 4
206+
207+
208+ def test_selecting_by_index_carries_document_ids ():
209+ """Slicing a corpus keeps each row pointing at the document it came from."""
210+ corpus = Corpus (documents = ["a" , "b" , "c" , "d" ], document_ids = np .array ([0 , 0 , 1 , 1 ]))
211+
212+ selected = corpus .get_corpus_by_indices ([1 , 2 ])
213+
214+ assert list (selected .document_ids ) == [0 , 1 ]
215+ assert selected .nr_documents == 2
216+
217+
218+ def test_selecting_by_topic_carries_document_ids ():
219+ corpus = Corpus (
220+ documents = ["a" , "b" , "c" ],
221+ document_ids = np .array ([0 , 0 , 1 ]),
222+ topics = np .array ([0 , 1 , 0 ]),
223+ )
224+
225+ selected = corpus .get_topic (0 )
226+
227+ assert list (selected .document_ids ) == [0 , 1 ]
228+
229+
230+ def test_combining_corpora_carries_document_ids ():
231+ """Zero-shot splits a corpus and recombines it, which must not renumber the rows."""
232+ first = Corpus (
233+ documents = ["first" ], topics = np .array ([0 ]), embeddings = np .zeros ((1 , 4 )), original_indices = [0 ]
234+ )
235+ second = Corpus (
236+ documents = ["second" ], topics = np .array ([1 ]), embeddings = np .ones ((1 , 4 )), original_indices = [1 ]
237+ )
238+
239+ combined = first + second
240+
241+ assert len (combined .document_ids ) == 2
242+
243+
244+ def test_mismatched_document_ids_are_rejected ():
245+ """A grouping key that is not one-per-row would silently misalign every later zip."""
246+ corpus = Corpus (documents = ["first" , "second" ])
247+
248+ with pytest .raises (ValueError ):
249+ corpus .document_ids = np .array ([0 ])
250+
251+
252+ def test_recombining_a_split_corpus_keeps_documents_distinct ():
253+ """Zero-shot builds two corpora from one input and adds them back together.
254+
255+ Each defaults its own ids, so numbering them from scratch would make row 0 of each
256+ half look like the same document. `original_indices` is what keeps them apart.
257+ """
258+ first = Corpus (
259+ documents = ["a" , "c" , "e" ],
260+ topics = np .array ([0 , 1 , 0 ]),
261+ embeddings = np .zeros ((3 , 4 )),
262+ original_indices = [0 , 2 , 4 ],
263+ )
264+ second = Corpus (
265+ documents = ["b" , "d" , "f" ],
266+ topics = np .array ([1 , 0 , 1 ]),
267+ embeddings = np .ones ((3 , 4 )),
268+ original_indices = [1 , 3 , 5 ],
269+ )
270+
271+ combined = first + second
272+
273+ assert combined .nr_documents == 6
0 commit comments