Skip to content

Commit 10bfa91

Browse files
lisaleemcbrcap107jeromedockes
authored
FEAT - Add a fetcher for the electricity forecasting dataset (#2013)
Co-authored-by: Riccardo Cappuzzo <7548232+rcap107@users.noreply.github.com> Co-authored-by: Jérôme Dockès <jerome@dockes.org>
1 parent 34d7e4d commit 10bfa91

6 files changed

Lines changed: 87 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ New Features
198198
- :func:`selectors.has_nulls` now takes a ``proportion`` parameter, which allows
199199
selecting columns that have a fraction of null values above the given threshold.
200200
:pr:`1881` by :user:`Gabriela Gómez Jiménez <gabrielapgomezji>`.
201+
- Added a new dataset, :func:`fetch_electricity_usage`, which contains electricity usage data
202+
for several French cities and corresponding weather data.
203+
:pr:`2013` by :user:`Lisa McBride<lisaleemcb>`.
201204

202205

203206
Changes

doc/api_reference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
"datasets.fetch_country_happiness",
328328
"datasets.fetch_credit_fraud",
329329
"datasets.fetch_drug_directory",
330+
"datasets.fetch_electricity_forecasting",
330331
"datasets.fetch_employee_salaries",
331332
"datasets.fetch_flight_delays",
332333
"datasets.fetch_medical_charge",

skrub/datasets/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
fetch_country_happiness,
2121
fetch_credit_fraud,
2222
fetch_drug_directory,
23+
fetch_electricity_forecasting,
2324
fetch_employee_salaries,
2425
fetch_flight_delays,
2526
fetch_medical_charge,
@@ -39,6 +40,7 @@
3940
"fetch_country_happiness",
4041
"fetch_credit_fraud",
4142
"fetch_drug_directory",
43+
"fetch_electricity_forecasting",
4244
"fetch_employee_salaries",
4345
"fetch_flight_delays",
4446
"fetch_medical_charge",

skrub/datasets/_fetching.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pathlib import Path
66

7-
from ._utils import load_dataset_files, load_simple_dataset
7+
from ._utils import download_dataset, load_dataset_files, load_simple_dataset
88

99

1010
def fetch_employee_salaries(data_home=None, split="all"):
@@ -606,3 +606,44 @@ def fetch_california_housing(data_home=None):
606606
The path to the california housing CSV file.
607607
"""
608608
return load_simple_dataset("california_housing", data_home)
609+
610+
611+
def fetch_electricity_forecasting(data_home=None):
612+
"""Fetches the electricity usage dataset (forecasting), available at \
613+
https://github.com/skrub-data/skrub-data-files
614+
615+
Description of the dataset:
616+
This dataset was generated from data obtained from the
617+
ENTSOE Open Data portal under the open source license (CC-BY 4.0):
618+
https://transparencyplatform.zendesk.com/hc/article_attachments/40921869376401
619+
620+
and the Open Meteo Historical Weather API:
621+
https://open-meteo.com/en/docs/historical-forecast-api
622+
in accordance with the licence described:
623+
https://open-meteo.com/en/licence
624+
625+
This is a time-series forecasting use case. This dataset gives the total
626+
electricity load in MW in France, covering a time range from
627+
March 23, 2021 to May 31, 2025. In addition, the dataset contains
628+
weather data for several cities within France.
629+
630+
It can be downloaded/loaded using the
631+
sklearn.datasets.fetch_electricity_forecasting function.
632+
Size on disk: 26MB.
633+
634+
Parameters
635+
----------
636+
data_home: str or path, default=None
637+
The directory where to download and unzip the files.
638+
639+
Returns
640+
-------
641+
Path : PosixPath
642+
The path to the electricity usage CSV files
643+
644+
References
645+
----------
646+
.. [1] For more detailed instructions on how to use this dataset, please refer
647+
to the example here: `EuroSciPy2025 <https://github.com/skrub-data/EuroSciPy2025>`_
648+
"""
649+
return download_dataset("electricity_forecasting", data_home=data_home)

skrub/datasets/_utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
],
5151
"sha256": "0c3885894baf02fc787109801ec2c34cc25cd4a31e0066a16941b74157474887",
5252
},
53+
"electricity_forecasting": {
54+
"urls": [
55+
"https://github.com/skrub-data/skrub-data-files/raw/refs/heads/main/electricity_forecasting.zip",
56+
"https://osf.io/download/d8ykq",
57+
],
58+
"sha256": "6ad239a828a5280deb4943c0f91be248483105fdd15f4544b878918671ca6113",
59+
},
5360
"employee_salaries": {
5461
"urls": [
5562
"https://github.com/skrub-data/skrub-data-files/raw/refs/heads/main/employee_salaries.zip",
@@ -245,7 +252,7 @@ def load_simple_dataset(dataset_name, data_home=None):
245252
return bunch
246253

247254

248-
def load_dataset_files(dataset_name, data_home):
255+
def download_dataset(dataset_name, data_home):
249256
data_home = get_data_home(data_home)
250257
dataset_dir = data_home / dataset_name
251258
datafiles_dir = dataset_dir / dataset_name
@@ -270,7 +277,11 @@ def load_dataset_files(dataset_name, data_home):
270277

271278
if not datafiles_dir.exists():
272279
_extract_archive(dataset_dir, archive_path)
280+
return datafiles_dir
281+
273282

283+
def load_dataset_files(dataset_name, data_home):
284+
datafiles_dir = download_dataset(dataset_name, data_home)
274285
bunch = Bunch()
275286

276287
# If there is a file named <dataset_name>.csv, we load the path as the main

skrub/datasets/tests/test_fetching.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from tempfile import TemporaryDirectory
23

34
import pandas as pd
@@ -174,3 +175,29 @@ def _error_on_get(*args, **kwargs):
174175
with TemporaryDirectory() as temp_dir:
175176
with pytest.raises(OSError, match="Can't download"):
176177
_ = _fetching.fetch_employee_salaries(data_home=temp_dir)
178+
179+
180+
@xfail_with_download_error
181+
def test_electricity_forecasting():
182+
files = set(
183+
[
184+
"weather_bayonne.csv",
185+
"weather_brest.csv",
186+
"weather_lille.csv",
187+
"weather_limoges.csv",
188+
"weather_lyon.csv",
189+
"weather_marseille.csv",
190+
"weather_nantes.csv",
191+
"weather_paris.csv",
192+
"weather_strasbourg.csv",
193+
"weather_toulouse.csv",
194+
"Total Load - Day Ahead _ Actual_202501010000-202601010000.csv",
195+
"Total Load - Day Ahead _ Actual_202401010000-202501010000.csv",
196+
"Total Load - Day Ahead _ Actual_202301010000-202401010000.csv",
197+
"Total Load - Day Ahead _ Actual_202201010000-202301010000.csv",
198+
"Total Load - Day Ahead _ Actual_202101010000-202201010000.csv",
199+
]
200+
)
201+
path = _fetching.fetch_electricity_forecasting()
202+
downloaded = [f.name for f in Path(path).iterdir() if f.is_file()]
203+
assert set(downloaded) == files

0 commit comments

Comments
 (0)