From b0ef47d2cbb880b06fb3bbe0c3eb66a6c9ef78a4 Mon Sep 17 00:00:00 2001 From: Mudit Atrey Date: Fri, 13 Mar 2026 22:21:54 +0530 Subject: [PATCH] DOC update remaining gallery examples to load datasets from paths --- CHANGES.rst | 5 ++++- .../FIXME/07_grid_searching_with_the_tablevectorizer.py | 7 +++++-- examples/data_ops/1110_data_ops_intro.py | 8 ++++++-- skrub/datasets/_fetching.py | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index e04d01357..880c9163b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -66,12 +66,15 @@ Bug Fixes - :class:`CheckInputDataFrame` no longer collects Polars LazyFrames automatically; a ``TypeError`` is now raised instead, consistent with the rest of the library. :pr:`1941` by :user:`Mudit Atrey `. +- :func:`fetch_employee_salaries` now correctly writes the train and test + split CSV files to their respective paths when ``split`` is specified. + :pr:`1964` by :user:`MuditAtrey `. Documentation ------------- - Updated gallery examples to load datasets from their file paths using ``pd.read_csv()``, following the pattern established in :pr:`1852`. - :pr:`1940` by :user:`MuditAtrey `. + :pr:`1940` and :pr:`1964` by :user:`MuditAtrey `. Release 0.7.2 ============= diff --git a/examples/FIXME/07_grid_searching_with_the_tablevectorizer.py b/examples/FIXME/07_grid_searching_with_the_tablevectorizer.py index 49249b6ae..104be28df 100644 --- a/examples/FIXME/07_grid_searching_with_the_tablevectorizer.py +++ b/examples/FIXME/07_grid_searching_with_the_tablevectorizer.py @@ -32,11 +32,14 @@ # # Throughout this example, we will use the employee salaries dataset. +import pandas as pd + from skrub.datasets import fetch_employee_salaries dataset = fetch_employee_salaries() -X = dataset.X -y = dataset.y +df = pd.read_csv(dataset.employee_salaries_path) +X = df.drop(columns=["current_annual_salary"]) +y = df["current_annual_salary"] X.head(10) diff --git a/examples/data_ops/1110_data_ops_intro.py b/examples/data_ops/1110_data_ops_intro.py index 561014be2..862e14af1 100644 --- a/examples/data_ops/1110_data_ops_intro.py +++ b/examples/data_ops/1110_data_ops_intro.py @@ -46,9 +46,13 @@ # By default, the |fetch_employee_salaries| function returns the training set. # We will load the test set later, to evaluate our model on unseen data. +import pandas as pd + from skrub.datasets import fetch_employee_salaries -training_data = fetch_employee_salaries(split="train").employee_salaries +training_data = pd.read_csv( + fetch_employee_salaries(split="train").employee_salaries_path +) # %% # We can take a look at the dataset using the |TableReport|. @@ -160,7 +164,7 @@ # case, "data"). # # We can now get the test set of the employee salaries dataset: -unseen_data = fetch_employee_salaries(split="test").employee_salaries +unseen_data = pd.read_csv(fetch_employee_salaries(split="test").employee_salaries_path) # %% # Then, we can use the loaded model to make predictions on the unseen data by diff --git a/skrub/datasets/_fetching.py b/skrub/datasets/_fetching.py index 5bd394e54..f42703c79 100644 --- a/skrub/datasets/_fetching.py +++ b/skrub/datasets/_fetching.py @@ -64,7 +64,7 @@ def fetch_employee_salaries(data_home=None, split="all"): ) dataset["employee_salaries_path"] = str(train_path) dataset["path"] = str(train_path) - dataset["employee_salaries"][:id_split].to_csv(str(train_path), index=False) + dataset["employee_salaries"].to_csv(str(train_path), index=False) dataset["X"] = dataset["X"][:id_split] dataset["y"] = dataset["y"][:id_split] elif split == "test": @@ -74,7 +74,7 @@ def fetch_employee_salaries(data_home=None, split="all"): ) dataset["employee_salaries_path"] = str(test_path) dataset["path"] = str(test_path) - dataset["employee_salaries"][id_split:].to_csv(str(test_path), index=False) + dataset["employee_salaries"].to_csv(str(test_path), index=False) dataset["X"] = dataset["X"][id_split:] dataset["y"] = dataset["y"][id_split:] return dataset