|
import os |
|
from pdb import set_trace |
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
Put your dataset citation here. |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Description of your dataset goes here. |
|
""" |
|
|
|
_HOMEPAGE = "https://your-dataset-homepage.com" |
|
|
|
_LICENSE = "License information goes here." |
|
|
|
|
|
class Test(datasets.GeneratorBasedBuilder): |
|
"""Your dataset description""" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="customers", |
|
version=datasets.Version("1.0.0"), |
|
description="This is subset A"), |
|
datasets.BuilderConfig( |
|
name="products", |
|
version=datasets.Version("1.0.0"), |
|
description="This is subset B"), |
|
] |
|
|
|
def _info(self): |
|
|
|
if self.config.name == "customers": |
|
features = datasets.Features( |
|
{ |
|
"customer_id": datasets.Value("int64"), |
|
"name": datasets.Value("string"), |
|
"age": datasets.Value("int64"), |
|
} |
|
) |
|
elif self.config.name == "products": |
|
features = datasets.Features( |
|
{ |
|
"product_id": datasets.Value("int64"), |
|
"name": datasets.Value("string"), |
|
"price": datasets.Value("double"), |
|
} |
|
) |
|
else: |
|
raise ValueError(f"Unknown subset: {self.config.name}") |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = dl_manager.manual_dir or "./" |
|
data_dir = os.path.join(data_dir, self.config.name) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": os.path.join(data_dir, "train.csv")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={"filepath": os.path.join(data_dir, "val.csv")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": os.path.join(data_dir, "test.csv")}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
df = pd.read_csv(filepath, index_col=0) |
|
for id_, item in df.iterrows(): |
|
yield id_, item.to_dict() |