| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import csv |
| import json |
| import os |
| from typing import List |
| import datasets |
| import logging |
|
|
|
|
| |
| _CITATION = """\ |
| @InProceedings{huggingface:dataset, |
| title = {TidyTuesday for Python}, |
| author={Holly Cui |
| }, |
| year={2024} |
| } |
| """ |
|
|
|
|
| _DESCRIPTION = """\ |
| This dataset compiles TidyTuesday datasets from 2023-2024, aiming to make resources in the R community more accessible for Python users. |
| """ |
|
|
|
|
| _HOMEPAGE = "https://huggingface.co/datasets/hollyyfc/tidytuesday_for_python" |
|
|
|
|
| _LICENSE = "" |
|
|
|
|
| _URLS = { |
| "full": "https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_json.json", |
| "train": "https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_json_train.json", |
| "validation": "https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_json_val.json" |
| } |
|
|
|
|
| class TidyTuesdayPython(datasets.GeneratorBasedBuilder): |
|
|
| _URLS = _URLS |
| VERSION = datasets.Version("1.1.0") |
|
|
|
|
| def _info(self): |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| "date_posted": datasets.Value("string"), |
| "project_name": datasets.Value("string"), |
| "project_source": datasets.features.Sequence(datasets.Value("string")), |
| "description": datasets.Value("string"), |
| "data_source_url": datasets.Value("string"), |
| "data_dictionary": datasets.features.Sequence( |
| { |
| "variable": datasets.Value("string"), |
| "class": datasets.Value("string"), |
| "description": datasets.Value("string"), |
| } |
| ), |
| "data": datasets.features.Sequence( |
| { |
| "file_name": datasets.Value("string"), |
| "file_url": datasets.Value("string"), |
| } |
| ), |
| "data_load": datasets.features.Sequence( |
| { |
| "file_name": datasets.Value("string"), |
| "file_url": datasets.Value("string"), |
| } |
| ), |
| } |
| ), |
| |
| supervised_keys=None, |
| |
| homepage=_HOMEPAGE, |
| |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
| urls_to_download = self._URLS |
| downloaded_files = dl_manager.download_and_extract(urls_to_download) |
| return [ |
| datasets.SplitGenerator( |
| name="full", |
| gen_kwargs={ |
| "filepath": downloaded_files["full"] |
| } |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": downloaded_files["train"] |
| } |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={ |
| "filepath": downloaded_files["validation"] |
| } |
| ), |
| ] |
|
|
| |
| def _generate_examples(self, filepath): |
| logging.info("generating examples from = %s", filepath) |
| with open(filepath, "r") as j: |
| tidytuesday_json = json.load(j) |
| |
| for record in tidytuesday_json: |
| id_ = record['date_posted'] |
| yield id_, record |
| ''' |
| yield id_, { |
| "project_name": record["project_name"], |
| "project_source": record["project_source"], |
| "description": record["description"], |
| "data_source_url": record["data_source_url"], |
| "data_dictionary": record["data_dictionary"], |
| "data": record["data"], |
| } |
| ''' |
|
|