|
|
|
|
|
import datasets |
|
|
|
import pyarrow as pa |
|
import pyarrow.parquet as pq |
|
|
|
BASE_DATASET = "ejschwartz/oo-method-test" |
|
|
|
class OOMethodTestDataset(datasets.ArrowBasedBuilder): |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="combined", |
|
version=datasets.Version("1.0.0"), |
|
description="All data files combined", |
|
), |
|
datasets.BuilderConfig( |
|
name="byrow", |
|
version=datasets.Version("1.0.0"), |
|
description="Split by example (dumb)", |
|
), |
|
datasets.BuilderConfig( |
|
name="byfuncname", |
|
version=datasets.Version("1.0.0"), |
|
description="Split by function name", |
|
) |
|
|
|
] |
|
|
|
def __init__(self, *args, **kwargs): |
|
super().__init__(*args, **kwargs) |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo() |
|
|
|
def _split_generators(self, dl_manager): |
|
ds = datasets.load_dataset(BASE_DATASET) |
|
|
|
|
|
|
|
|
|
if self.config.name == "combined": |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="combined", |
|
gen_kwargs={ |
|
"ds": ds['combined'], |
|
}, |
|
), |
|
] |
|
|
|
elif self.config.name == "byrow": |
|
|
|
ds = ds['combined'].train_test_split(test_size=0.1, seed=42) |
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="train", |
|
gen_kwargs={ |
|
"ds": ds['train'], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name="test", |
|
gen_kwargs={ |
|
"ds": ds['test'], |
|
}, |
|
), |
|
|
|
] |
|
|
|
elif self.config.name == "byfuncname": |
|
|
|
ds = ds['combined'] |
|
|
|
unique_names = ds.unique('Name') |
|
nameds = datasets.Dataset.from_dict({'Name': unique_names}) |
|
|
|
name_split = nameds.train_test_split(test_size=0.1, seed=42) |
|
|
|
|
|
train_name = name_split['train']['Name'] |
|
test_name = name_split['test']['Name'] |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="train", |
|
gen_kwargs={ |
|
"ds": ds.filter(lambda r: r['Name'] in train_name), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name="test", |
|
gen_kwargs={ |
|
"ds": ds.filter(lambda r: r['Name'] in test_name), |
|
}, |
|
), |
|
|
|
] |
|
|
|
else: |
|
assert False |
|
|
|
def _generate_tables(self, ds): |
|
|
|
|
|
|
|
for i, batch in enumerate(ds.to_pandas(batched=True)): |
|
yield i, pa.Table.from_pandas(batch) |
|
|