hollyyfc commited on
Commit
2d0edd4
1 Parent(s): cbc3811

Upload tidytuesday_for_python.py

Browse files
Files changed (1) hide show
  1. tidytuesday_for_python.py +129 -0
tidytuesday_for_python.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ import csv
17
+ import json
18
+ import os
19
+ from typing import List
20
+ import datasets
21
+ import logging
22
+
23
+
24
+ # Find for instance the citation on arxiv or on the dataset repo/website
25
+ _CITATION = """\
26
+ @InProceedings{huggingface:dataset,
27
+ title = {TidyTuesday for Python},
28
+ author={Holly Cui
29
+ },
30
+ year={2024}
31
+ }
32
+ """
33
+
34
+
35
+ _DESCRIPTION = """\
36
+ This dataset compiles TidyTuesday datasets from 2023-2024, aiming to make resources in the R community more accessible for Python users.
37
+ """
38
+
39
+
40
+ _HOMEPAGE = ""
41
+
42
+
43
+ _LICENSE = ""
44
+
45
+
46
+ _URLS = {
47
+ "train": "https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_json_train.json",
48
+ "validation": "https://raw.githubusercontent.com/hollyyfc/tidytuesday-for-python/main/tidytuesday_json_val.json",
49
+ }
50
+
51
+
52
+ class TidyTuesdayPython(datasets.GeneratorBasedBuilder):
53
+
54
+ _URLS = _URLS
55
+ VERSION = datasets.Version("1.1.0")
56
+
57
+ BUILDER_CONFIGS = [
58
+ datasets.BuilderConfig(name="train", version=VERSION, description="This part of my dataset covers the train set"),
59
+ datasets.BuilderConfig(name="validation", version=VERSION, description="This part of my dataset covers the validation set"),
60
+ ]
61
+
62
+ DEFAULT_CONFIG_NAME = "train"
63
+
64
+
65
+ def _info(self):
66
+
67
+ return datasets.DatasetInfo(
68
+ description=_DESCRIPTION,
69
+ features=datasets.Features(
70
+ {
71
+ "date_posted": datasets.Value("string"),
72
+ "project_name": datasets.Value("string"),
73
+ "project_source": datasets.features.Sequence(datasets.Value("string")),
74
+ "description": datasets.Value("string"),
75
+ "data_source_url": datasets.Value("string"),
76
+ "data_dictionary": datasets.features.Sequence(
77
+ {
78
+ "variable": datasets.Value("string"),
79
+ "class": datasets.Value("string"),
80
+ "description": datasets.Value("string"),
81
+ }
82
+ ),
83
+ "data": datasets.features.Sequence(
84
+ {
85
+ "file_name": datasets.Value("string"),
86
+ "file_url": datasets.Value("string"),
87
+ }
88
+ ),
89
+ "data_load": datasets.features.Sequence(
90
+ {
91
+ "file_name": datasets.Value("string"),
92
+ "load_url": datasets.Value("string"),
93
+ }
94
+ ),
95
+ }
96
+ ),
97
+ # No default supervised_keys (as we have to pass both premise
98
+ supervised_keys=None,
99
+ # Homepage of the dataset for documentation
100
+ homepage=_HOMEPAGE,
101
+ # Citation for the dataset
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
106
+ urls_to_download = self._URLS
107
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
108
+ return [
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TRAIN,
111
+ gen_kwargs={
112
+ "filepath": downloaded_files["train"]
113
+ }
114
+ ),
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.VALIDATION,
117
+ gen_kwargs={
118
+ "filepath": downloaded_files["validation"]
119
+ }
120
+ ),
121
+ ]
122
+
123
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
124
+ def _generate_examples(self, filepath):
125
+ logging.info("generating examples from = %s", filepath)
126
+ with open(filepath, "r") as j:
127
+ tidytuesday_json = json.load()
128
+ for record in tidytuesday_json:
129
+ yield record