Skip to content

Make all non-canonical modules private? #9250

Closed

Description

@amueller

This is maybe for 1.0. Recently we started marking files like model_selection._split private, so that everything has a single canonical import:

from sklearn.model_selection import cross_val_score

For many (older?) models that's not the case, we have

from sklearn.linear_model.logistic import LogisticRegression
from sklearn.linear_model import LogisticRegression

etc.
I think it would be nice to make all the files that are not the canonical import (according to the API documentation) private (with deprecation obviously).
That might be a bit annoying for existing users that used long import paths, but it makes auto-complete much more helpful and the module structure much less confusing for newcomers.

For example sklearn.linear_model.ridge is a module, while sklearn.linear_model.ridge_regression is a function that implements ridge regression and sklearn.linear_model.Ridge is a class that implements ridge regression. From the names this is totally unclear.

Activity

  1. added this to the 1.0 milestone on Jun 29, 2017
  2. jmschrei commented on Jun 29, 2017

    @jmschrei
    Member

    I would support this as it seems like it could clear up a lot of confusion. Do you believe there are any people directly trying to use the functions that would be made private?

  3. jnothman commented on Jun 29, 2017

    @jnothman
    Member
  4. modified the milestones: 1.0, 0.22 on Sep 10, 2019
  5. adrinjalali commented on Sep 10, 2019

    @adrinjalali
    Member

    Since #14939 is merged, we seem to be deprecating them already for 0.22. This now seems like an easy one for some of the upcoming sprints. Although if we want it done before the end of october, we should do it ourselves maybe.

  6. NicolasHug commented on Sep 10, 2019

    @NicolasHug
    Member

    Below is the list of the folders whose files need to be preceded by an underscore. The procedure is pretty straightforward:

    • rename file.py into _file.py and create a new file.py with a similar content that raises a deprecation warning (like neural_network/rbm.py)
    • update __init__.py
    • update test parametrization of sklearn/tests/test_import_deprecations.py

    Folders

    (Note that this only addresses the folders. Files like sklearn/pipeline.py may still contain non-deprecated things.)

  7. NicolasHug commented on Sep 10, 2019

    @NicolasHug
    Member

    ping @thomasjpfan @glemaitre @adrinjalali let's pick one each and review each-other? this should go relatively fast

    I'll pick cluster

  8. adrinjalali commented on Sep 11, 2019

    @adrinjalali
    Member

    I'm taking the tree and ensemble, since they're interrelated.

  9. glemaitre commented on Sep 12, 2019

    @glemaitre
    Member

    I'll take preprocessing and inspection at first

  10. amueller commented on Sep 18, 2019

    @amueller
    MemberAuthor

    pretty sure folks have not been using git move correctly. Try doing a single commit that does the move and commit that, before adding anything else. Your PRs don't show files as moved, which means that something went wrong.

  11. jnothman commented on Sep 18, 2019

    @jnothman
    Member
  12. adrinjalali commented on Sep 19, 2019

    @adrinjalali
    Member

    I did move, as you see in this commit df7f54d but once you create a file with the same name, github gets confused.

  13. NicolasHug commented on Oct 9, 2019

    @NicolasHug
    Member

    I'm working on mixture and svm

  14. 10 remaining items

  15. thomasjpfan commented on Oct 21, 2019

    @thomasjpfan
    Member

    Working on inspection

  16. thomasjpfan commented on Oct 21, 2019

    @thomasjpfan
    Member

    Working on preprocessing

  17. thomasjpfan commented on Oct 21, 2019

    @thomasjpfan
    Member

    Working on linear_models

  18. glemaitre commented on Oct 23, 2019

    @glemaitre
    Member

    @thomasjpfan From the list, I only did not review the PR for the decomposition. I did not open a PR because you seem to have work on it. Could you open a PR?

  19. qinhanmin2014 commented on Oct 28, 2019

    @qinhanmin2014
    Member

    ping @NicolasHug @thomasjpfan what about sklearn.feature_selection?

    Is #15367 a blocker?

  20. thomasjpfan commented on Oct 28, 2019

    @thomasjpfan
    Member

    Working on feature_selection

  21. NicolasHug commented on Oct 28, 2019

    @NicolasHug
    Member

    what about sklearn.feature_selection?

    Thanks I missed this one

    Is #15367 a blocker?

    Yes but it's tracked by another issue

  22. lucasdavid commented on Dec 23, 2019

    @lucasdavid

    I had a ton of private datasets, such as names, text and geographical data. I used to use the following utils to download and manage these:

    from sklearn.datasets.base import (get_data_home, RemoteFileMetadata, _fetch_remote)

    What's the recommended approach now?

  23. glemaitre commented on Dec 23, 2019

    @glemaitre
    Member

    you can import from sklearn.datasets._base import ...

    However, now you are aware that _base will be private and you might have to change your code at a new scikit-learn release since we might not provide backward-compatible code.

    This said, be aware that we are going to define a developer API which will define some backward support for these types of utilities used in third-party.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions