Skip to content

Add fetch()/fetch_<name>() dataset API to skimage2 - #8285

Open
blink1073 wants to merge 21 commits into
scikit-image:mainfrom
blink1073:skimage2-fetch-api
Open

blink1073 wants to merge 21 commits into
scikit-image:mainfrom
blink1073:skimage2-fetch-api

Conversation

@blink1073

@blink1073 blink1073 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Add skimage2.data.fetch() and a fetch_<name>() wrapper function per dataset, following the pattern of sklearn.datasets.fetch_*. The prefix makes it explicit at the call site that a dataset may need downloading.

The bare names (astronaut, camera, ...) will remain importable during the overlap with skimage1, but skimage2 now points users to the fetch_ wrappers, and the rename is documented in the skimage2 migration guide. The data API for skimage (v1) is unchanged.

pytest on Python 3.12: 18757 passed (65 skipped, 194 xfailed for optional dependencies).

Developed with Claude Code, with all changes and test results reviewed.

Release note (optional)

Add ``fetch()`` to ``skimage2.data``, plus a convenience wrapper for each
dataset, such as ``fetch_astronaut()``, named after the pattern used by
``sklearn.datasets``. The bare dataset names still work, as aliases of the new
wrappers. ``skimage.data`` is unaffected.

Introduce a generic fetch() plus sklearn-style fetch_<name>() wrappers
for every dataset getter, following the pattern of
sklearn.datasets.fetch_* (e.g. fetch_lfw_people). The names make it
explicit at the call site that a dataset may need to be downloaded.

The bare names (astronaut, camera, ...) are dropped from
_skimage2.data's public surface. They remain in _fetchers.py, since
skimage1's shim imports them straight from there, bypassing
_skimage2.data's public API, so skimage1 is unchanged.

skimage1 and skimage2 share docstrings, so _doctest_adapters strips the
fetch_ prefix when adapting examples for skimage1, which keeps calling
the bare names.
@greptile-apps

greptile-apps Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Add skimage2's fetch()/fetch_<name>() da..." | Re-trigger Greptile

@blink1073 blink1073 changed the title Add skimage2's fetch()/fetch_<name>() dataset API Add fetch()/fetch_<name>() dataset API to skimage2 Aug 15, 2026
The docstring was written against the follow-up CDN work: it claimed
pooch is a normal dependency and that files may come from a
scikit-image-data package. Neither holds here. pooch is still optional,
carried by the data extra, and scikit-image-data does not exist yet.

Describe the resolution order that this branch actually implements, and
match the wording _fetch() already uses for the same error.
Readers moving to skimage2 need to know that data.astronaut() is now
data.fetch_astronaut(). Add a hand-written section rather than a
migration decorator entry, since skimage1 keeps the bare names and
nothing is being deprecated there.
Cut the sentence in fetch()'s docstring that restated what the wrappers
already show, and trim the alias comment to the part the code does not
say: why the bare names stay in this module.
fetch_astronaut() and friends are now aliases alongside the bare
astronaut() names, not replacements for them, so existing skimage2
code keeps working. Update the migration guide and the public-surface
test to match.
The .pyi comment called the bare names "aliases of the fetch_*()
functions" -- backwards: astronaut is the original, fetch_astronaut =
astronaut is the alias. Also cut a sentence in _fetchers.py that only
restated what the assignment below it already shows.
fetch_*() is the canonical API; the bare names (e.g. astronaut) stay
importable as aliases but leave __all__ and __dir__ so the API reference
and tab completion surface only fetch_*. attach_stub derives runtime
__all__ from the stub imports, so __init__.py overrides __all__/__dir__
explicitly and the stub keeps the bare names as `x as x` re-exports.
@blink1073 blink1073 closed this Sep 5, 2026
@blink1073 blink1073 reopened this Sep 12, 2026
The doctest adapter stripped the fetch_ prefix from any identifier, which
could silently corrupt unrelated fetch_* references. Scope it to the
known dataset fetcher names so only those are rewritten, and add tests
covering both the strip and the no-op cases. Drop the unrelated uv.lock
gitignore entry. Also add a test asserting the bare v1 alias (e.g.
data.astronaut) is importable and usable but absent from __all__.
Merging upstream main (which includes scikit-image#8310: physical skimage2 sub-package
shims) makes skimage2.data a distinct shim module, not the same module as
_skimage2.data. The test asserted module identity, which now fails in CI.
Assert instead that the shim forwards to the same objects and exposes the
same __all__.
test_skimage2_modules_match asserted the ExperimentalAPIWarning fires on
'import skimage2'. My data-surface test imports skimage2 first (with the
warning suppressed), so under parallel and Pyodide runs the module is
already cached and the warning never re-fires, failing the test. Reload
the module inside the assertion to guarantee a fresh import.
Preparing the data-fetcher rename: the bare dataset names (e.g. astronaut)
are replaced by the fetch_<name>() wrappers.

On the skimage2 side, calling skimage2.data.astronaut() now emits a
DeprecationWarning pointing to fetch_astronaut. The bare name stays
importable during the overlap period while skimage (v1) is maintained, and
will be dropped when v1 support is removed. The wrappers are cached so
repeated attribute access returns one object.

On the skimage (v1) side, the bare names remain the primary API but emit a
PendingSkimage2Change warning directing users to the skimage2.fetch_*
counterparts; both namespaces stay available during the overlap period.

Tests now assert return-value equality between bare and fetch_ names rather
than function identity, and verify the deprecation and migration warnings.
The migration guide documents the rename once, without per-function entries.
@blink1073
blink1073 marked this pull request as ready for review September 27, 2026 22:20
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

This AI review is meant to assist maintainers with quick spot checks. You don't need to act on it until you hear from a maintainer.

Retrigger

[Medium risk] Updates dataset API naming across the library.

The PR appears safe to merge; no new actionable issue was established.

Reviews (3) · Last reviewed commit: "Merge branch 'skimage2-fetch-api' of git..."

lazy_loader caches resolved names in the module __dict__, and eagerly
binds every stub name when EAGER_IMPORT is set, so the bare dataset
names shadowed their deprecation wrappers after the first access (and
were never wrapped at all under eager import). Resolve through the
canonical fetch_* name, cache the wrapper in globals, and re-wrap any
bare names already bound by eager import.
@stefanv stefanv added the 🥾 Path to skimage2 A step towards the new "API 2.0" label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🥾 Path to skimage2 A step towards the new "API 2.0"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants