MCPcopy Create free account
hub / github.com/InternScience/SciReason / _check_data

Function _check_data

tests/dataset/test_local_datasets.py:181–225  ·  view source on GitHub ↗
(ms_dataset: Dataset | DatasetDict,
                oc_dataset: Dataset | DatasetDict,
                sample_size)

Source from the content-addressed store, hash-verified

179
180
181def _check_data(ms_dataset: Dataset | DatasetDict,
182 oc_dataset: Dataset | DatasetDict,
183 sample_size):
184 assert type(ms_dataset) == type(
185 oc_dataset
186 ), f'Dataset type not match: {type(ms_dataset)} != {type(oc_dataset)}'
187
188 # match DatasetDict
189 if isinstance(oc_dataset, DatasetDict):
190 assert ms_dataset.keys() == oc_dataset.keys(
191 ), f'DatasetDict not match: {ms_dataset.keys()} != {oc_dataset.keys()}'
192
193 for key in ms_dataset.keys():
194 _check_data(ms_dataset[key], oc_dataset[key], sample_size=sample_size)
195
196 elif isinstance(oc_dataset, Dataset):
197 # match by cols
198 assert set(ms_dataset.column_names) == set(
199 oc_dataset.column_names
200 ), f'Column names do not match: {ms_dataset.column_names} != {oc_dataset.column_names}'
201
202 # Check that the number of rows is the same
203 assert len(ms_dataset) == len(
204 oc_dataset
205 ), f'Number of rows do not match: {len(ms_dataset)} != {len(oc_dataset)}'
206
207 # Randomly sample indices
208 sample_indices = random.sample(range(len(ms_dataset)),
209 min(sample_size, len(ms_dataset)))
210
211 for i, idx in enumerate(sample_indices):
212 for col in ms_dataset.column_names:
213 ms_value = clean_string(str(ms_dataset[col][idx]))
214 oc_value = clean_string(str(oc_dataset[col][idx]))
215 try:
216 assert ms_value == oc_value, f"Value mismatch in column '{col}', index {idx}: {ms_value} != {oc_value}"
217 except AssertionError as e:
218 print(f"Assertion failed for column '{col}', index {idx}")
219 print(f"ms_data: {ms_dataset[idx]}")
220 print(f'oc_data: {oc_dataset[idx]}')
221 print(f'ms_value: {ms_value} ({type(ms_value)})')
222 print(f'oc_value: {oc_value} ({type(oc_value)})')
223 raise e
224 else:
225 raise ValueError(f'Datasets type not supported {type(ms_dataset)}')
226
227
228if __name__ == '__main__':

Callers

nothing calls this directly

Calls 1

clean_stringFunction · 0.70

Tested by

no test coverage detected