kashif HF Staff commited on
Commit
6b2eb0e
·
verified ·
1 Parent(s): eb0f9a9

Remove deprecated dataset script (not supported in datasets>=3.0)

Browse files
Files changed (1) hide show
  1. chronos_datasets_extra.py +0 -208
chronos_datasets_extra.py DELETED
@@ -1,208 +0,0 @@
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
- import tempfile
15
- from pathlib import Path
16
-
17
- import datasets
18
- import pandas as pd
19
-
20
- _VERSION = "1.0.0"
21
-
22
- _DESCRIPTION = "Chronos datasets"
23
-
24
- _CITATION = """
25
- @article{ansari2024chronos,
26
- author = {Ansari, Abdul Fatir and Stella, Lorenzo and Turkmen, Caner and Zhang, Xiyuan, and Mercado, Pedro and Shen, Huibin and Shchur, Oleksandr and Rangapuram, Syama Syndar and Pineda Arango, Sebastian and Kapoor, Shubham and Zschiegner, Jasper and Maddix, Danielle C. and Wang, Hao and Mahoney, Michael W. and Torkkola, Kari and Gordon Wilson, Andrew and Bohlke-Schneider, Michael and Wang, Yuyang},
27
- title = {Chronos: Learning the Language of Time Series},
28
- journal = {arXiv preprint arXiv:2403.07815},
29
- year = {2024}
30
- }
31
- """
32
-
33
-
34
- _ETTH = "ETTh"
35
- _ETTM = "ETTm"
36
- _SPANISH_ENERGY_AND_WEATHER = "spanish_energy_and_weather"
37
- _BRAZILIAN_TEMPERATURE = "brazilian_cities_temperature"
38
-
39
-
40
- class ChronosExtraConfig(datasets.BuilderConfig):
41
- def __init__(
42
- self,
43
- name: str,
44
- license: str = None,
45
- homepage: str = None,
46
- **kwargs,
47
- ):
48
- super().__init__(name=name, **kwargs)
49
- self.license = license
50
- self.homepage = homepage
51
-
52
-
53
- class ChronosExtraBuilder(datasets.GeneratorBasedBuilder):
54
- BUILDER_CONFIG_CLASS = ChronosExtraConfig
55
- BUILDER_CONFIGS = [
56
- ChronosExtraConfig(
57
- name=_ETTH,
58
- license="CC BY-ND 4.0",
59
- homepage="https://github.com/zhouhaoyi/ETDataset",
60
- version=_VERSION,
61
- ),
62
- ChronosExtraConfig(
63
- name=_ETTM,
64
- license="CC BY-ND 4.0",
65
- homepage="https://github.com/zhouhaoyi/ETDataset",
66
- version=_VERSION,
67
- ),
68
- ChronosExtraConfig(
69
- name=_BRAZILIAN_TEMPERATURE,
70
- license="Database Contents License (DbCL) v1.0",
71
- homepage="https://www.kaggle.com/datasets/volpatto/temperature-timeseries-for-some-brazilian-cities",
72
- version=_VERSION,
73
- ),
74
- ChronosExtraConfig(
75
- name=_SPANISH_ENERGY_AND_WEATHER,
76
- homepage="https://www.kaggle.com/datasets/nicholasjhana/energy-consumption-generation-prices-and-weather",
77
- version=_VERSION,
78
- ),
79
- ]
80
-
81
- def _info(self):
82
- return datasets.DatasetInfo(
83
- description=_DESCRIPTION,
84
- citation=_CITATION,
85
- version=self.config.version,
86
- license=self.config.license,
87
- homepage=self.config.homepage,
88
- )
89
-
90
- def _split_generators(self, dl_manager):
91
- return [
92
- datasets.SplitGenerator(name=datasets.Split.TRAIN),
93
- ]
94
-
95
- def _generate_examples(self):
96
- if self.config.name in [_ETTH, _ETTM]:
97
- yield from _ett_generator(self.config.name)
98
- elif self.config.name == _SPANISH_ENERGY_AND_WEATHER:
99
- yield from _spanish_energy_generator()
100
- elif self.config.name == _BRAZILIAN_TEMPERATURE:
101
- yield from _brazilian_temperature_generator()
102
-
103
-
104
- def _ett_generator(name: str):
105
- for region in [1, 2]:
106
- url = f"https://raw.githubusercontent.com/zhouhaoyi/ETDataset/main/ETT-small/{name}{region}.csv?download=1"
107
- df = pd.read_csv(url, parse_dates=["date"])
108
- df = df.rename(columns={"date": "timestamp"})
109
- entry = {"id": f"{name}{region}"}
110
- for col in df.columns:
111
- entry[col] = df[col].to_numpy()
112
- yield region, entry
113
-
114
-
115
- def _download_from_kaggle(dataset_name, download_path) -> None:
116
- from kaggle.api.kaggle_api_extended import KaggleApi
117
-
118
- api = KaggleApi()
119
- api.authenticate()
120
- api.dataset_download_files(dataset_name, path=download_path, unzip=True)
121
-
122
-
123
- def _spanish_energy_generator():
124
- with tempfile.TemporaryDirectory() as download_path:
125
- _download_from_kaggle(
126
- "nicholasjhana/energy-consumption-generation-prices-and-weather",
127
- download_path,
128
- )
129
- download_path = Path(download_path)
130
- df_energy = pd.read_csv(download_path / "energy_dataset.csv")
131
- df_energy["time"] = pd.to_datetime(df_energy["time"], utc=True)
132
- df_energy.set_index("time", inplace=True)
133
-
134
- # Drop non-informative columns / columns containing forecasts
135
- constant_columns = df_energy.columns[df_energy.nunique() <= 1].to_list()
136
- forecast_columns = [
137
- col for col in df_energy.columns if "forecast" in col or "day ahead" in col
138
- ]
139
- columns_to_drop = constant_columns + forecast_columns
140
- df_energy = df_energy.drop(columns_to_drop, axis=1)
141
-
142
- entry = {"id": "0", "timestamp": df_energy.index.to_numpy(dtype="datetime64[ms]")}
143
- for col in df_energy.columns:
144
- saved_name = col.replace(" ", "_")
145
- entry[saved_name] = df_energy[col].to_numpy(dtype="float64")
146
-
147
- # Weather data
148
- df_weather = pd.read_csv(download_path / "weather_features.csv")
149
- df_weather["dt_iso"] = pd.to_datetime(df_weather["dt_iso"], utc=True)
150
- df_weather = (
151
- df_weather.rename(columns={"dt_iso": "time"})
152
- .drop_duplicates(subset=["time", "city_name"], keep="first")
153
- .set_index("time")
154
- )
155
- weather_features = [
156
- "temp",
157
- "temp_min",
158
- "temp_max",
159
- "pressure",
160
- "humidity",
161
- "wind_speed",
162
- "wind_deg",
163
- "rain_1h",
164
- "snow_3h",
165
- "clouds_all",
166
- ]
167
- for feature in weather_features:
168
- for city, df_for_city in df_weather.groupby("city_name"):
169
- saved_name = f"{city.lstrip()}_{feature}"
170
- entry[saved_name] = df_for_city[feature].to_numpy(dtype="float64")
171
- assert df_for_city.index.equals(df_energy.index)
172
- yield 0, entry
173
-
174
-
175
- def _brazilian_temperature_generator():
176
- months = [
177
- "JAN",
178
- "FEB",
179
- "MAR",
180
- "APR",
181
- "MAY",
182
- "JUN",
183
- "JUL",
184
- "AUG",
185
- "SEP",
186
- "OCT",
187
- "NOV",
188
- "DEC",
189
- ]
190
- with tempfile.TemporaryDirectory() as download_path:
191
- _download_from_kaggle(
192
- "volpatto/temperature-timeseries-for-some-brazilian-cities", download_path
193
- )
194
- for filename in sorted(Path(download_path).iterdir()):
195
- city = filename.name.split("_", maxsplit=1)[1].split(".")[0]
196
- df = pd.read_csv(filename)
197
- df = df.set_index("YEAR")[months]
198
- first_timestamp = f"{df.index[0]}-01-01"
199
- df = df.stack()
200
- df[df == 999.9] = float("nan")
201
- entry = {
202
- "id": city,
203
- "timestamp": pd.date_range(
204
- first_timestamp, freq="MS", periods=len(df), unit="ms"
205
- ).to_numpy(),
206
- "temperature": df.to_numpy("float32"),
207
- }
208
- yield city, entry