Skip to content

[MRG] MNT Make modules private in neighbors #15322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ sklearn/svm/libsvm.py
sklearn/svm/libsvm_sparse.py
sklearn/svm/liblinear.py

sklearn/neighbors/ball_tree.py
sklearn/neighbors/base.py
sklearn/neighbors/classification.py
sklearn/neighbors/dist_metrics.py
sklearn/neighbors/graph.py
sklearn/neighbors/kd_tree.py
sklearn/neighbors/kde.py
sklearn/neighbors/lof.py
sklearn/neighbors/nca.py
sklearn/neighbors/nearest_centroid.py
sklearn/neighbors/quad_tree.py
sklearn/neighbors/regression.py
sklearn/neighbors/typedefs.py
sklearn/neighbors/unsupervised.py

sklearn/manifold/isomap.py
sklearn/manifold/locally_linear.py
sklearn/manifold/mds.py
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/density.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ It's clear how the kernel shape affects the smoothness of the resulting
distribution. The scikit-learn kernel density estimator can be used as
follows:

>>> from sklearn.neighbors.kde import KernelDensity
>>> from sklearn.neighbors import KernelDensity
>>> import numpy as np
>>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(X)
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/neighbors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ and Quadratic Discriminant Analysis (:class:`sklearn.discriminant_analysis.Quadr
for more complex methods that do not make this assumption. Usage of the default
:class:`NearestCentroid` is simple:

>>> from sklearn.neighbors.nearest_centroid import NearestCentroid
>>> from sklearn.neighbors import NearestCentroid
>>> import numpy as np
>>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> y = np.array([1, 1, 1, 2, 2, 2])
Expand Down
29 changes: 29 additions & 0 deletions sklearn/_build_utils/deprecated_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@
'set_verbosity_wrap'),
('_liblinear', 'sklearn.svm.liblinear', 'sklearn.svm', 'train_wrap'),

('_ball_tree', 'sklearn.neighbors.ball_tree', 'sklearn.neighbors',
'BallTree'),
('_base', 'sklearn.neighbors.base', 'sklearn.neighbors',
'VALID_METRICS'),
('_classification', 'sklearn.neighbors.classification',
'sklearn.neighbors', 'KNeighborsClassifier'),
('_dist_metrics', 'sklearn.neighbors.dist_metrics', 'sklearn.neighbors',
'DistanceMetric'),
('_graph', 'sklearn.neighbors.graph', 'sklearn.neighbors',
'KNeighborsTransformer'),
('_kd_tree', 'sklearn.neighbors.kd_tree', 'sklearn.neighbors',
'KDTree'),
('_kde', 'sklearn.neighbors.kde', 'sklearn.neighbors',
'KernelDensity'),
('_lof', 'sklearn.neighbors.lof', 'sklearn.neighbors',
'LocalOutlierFactor'),
('_nca', 'sklearn.neighbors.nca', 'sklearn.neighbors',
'NeighborhoodComponentsAnalysis'),
('_nearest_centroid', 'sklearn.neighbors.nearest_centroid',
'sklearn.neighbors', 'NearestCentroid'),
('_quad_tree', 'sklearn.neighbors.quad_tree', 'sklearn.neighbors',
'CELL_DTYPE'),
('_regression', 'sklearn.neighbors.regression', 'sklearn.neighbors',
'KNeighborsRegressor'),
('_typedefs', 'sklearn.neighbors.typedefs', 'sklearn.neighbors',
'DTYPE'),
('_unsupervised', 'sklearn.neighbors.unsupervised', 'sklearn.neighbors',
'NearestNeighbors'),

('_isomap', 'sklearn.manifold.isomap', 'sklearn.manifold', 'Isomap'),
('_locally_linear', 'sklearn.manifold.locally_linear', 'sklearn.manifold',
'LocallyLinearEmbedding'),
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/tests/test_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from sklearn.metrics.pairwise import PAIRED_DISTANCES, cosine_distances,\
manhattan_distances, pairwise_distances
from sklearn.metrics.cluster import normalized_mutual_info_score
from sklearn.neighbors.graph import kneighbors_graph
from sklearn.neighbors import kneighbors_graph
from sklearn.cluster._hierarchical_fast import average_merge, max_merge
from sklearn.utils._fast_dict import IntFloatDict
from sklearn.utils.testing import assert_array_equal
Expand Down
4 changes: 2 additions & 2 deletions sklearn/impute/_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from ..utils.validation import FLOAT_DTYPES
from ..metrics import pairwise_distances
from ..metrics.pairwise import _NAN_METRICS
from ..neighbors.base import _get_weights
from ..neighbors.base import _check_weights
from ..neighbors._base import _get_weights
from ..neighbors._base import _check_weights
from ..utils import check_array
from ..utils import is_scalar_nan
from ..utils._mask import _get_mask
Expand Down
2 changes: 1 addition & 1 deletion sklearn/manifold/_barnes_hut_tsne.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from libc.math cimport sqrt, log
import numpy as np
cimport numpy as np

from ..neighbors.quad_tree cimport _QuadTree
from ..neighbors._quad_tree cimport _QuadTree

cdef char* EMPTY_STRING = ""

Expand Down
26 changes: 13 additions & 13 deletions sklearn/neighbors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
algorithm.
"""

from .ball_tree import BallTree
from .kd_tree import KDTree
from .dist_metrics import DistanceMetric
from .graph import kneighbors_graph, radius_neighbors_graph
from .graph import KNeighborsTransformer, RadiusNeighborsTransformer
from .unsupervised import NearestNeighbors
from .classification import KNeighborsClassifier, RadiusNeighborsClassifier
from .regression import KNeighborsRegressor, RadiusNeighborsRegressor
from .nearest_centroid import NearestCentroid
from .kde import KernelDensity
from .lof import LocalOutlierFactor
from .nca import NeighborhoodComponentsAnalysis
from .base import VALID_METRICS, VALID_METRICS_SPARSE
from ._ball_tree import BallTree
from ._kd_tree import KDTree
from ._dist_metrics import DistanceMetric
from ._graph import kneighbors_graph, radius_neighbors_graph
from ._graph import KNeighborsTransformer, RadiusNeighborsTransformer
from ._unsupervised import NearestNeighbors
from ._classification import KNeighborsClassifier, RadiusNeighborsClassifier
from ._regression import KNeighborsRegressor, RadiusNeighborsRegressor
from ._nearest_centroid import NearestCentroid
from ._kde import KernelDensity
from ._lof import LocalOutlierFactor
from ._nca import NeighborhoodComponentsAnalysis
from ._base import VALID_METRICS, VALID_METRICS_SPARSE

__all__ = ['BallTree',
'DistanceMetric',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ VALID_METRICS = ['EuclideanDistance', 'SEuclideanDistance',
'PyFuncDistance', 'HaversineDistance']


include "binary_tree.pxi"
include "_binary_tree.pxi"

# Inherit BallTree from BinaryTree
cdef class BallTree(BinaryTree):
Expand Down
4 changes: 2 additions & 2 deletions sklearn/neighbors/base.py → sklearn/neighbors/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import joblib
from joblib import Parallel, delayed, effective_n_jobs

from .ball_tree import BallTree
from .kd_tree import KDTree
from ._ball_tree import BallTree
from ._kd_tree import KDTree
from ..base import BaseEstimator, MultiOutputMixin
from ..metrics import pairwise_distances_chunked
from ..metrics.pairwise import PAIRWISE_DISTANCE_FUNCTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ import numpy as np
import warnings
from ..utils import check_array

from .typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t
from .typedefs import DTYPE, ITYPE
from ._typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t
from ._typedefs import DTYPE, ITYPE

from .dist_metrics cimport (DistanceMetric, euclidean_dist, euclidean_rdist,
euclidean_dist_to_rdist, euclidean_rdist_to_dist)
from ._dist_metrics cimport (DistanceMetric, euclidean_dist, euclidean_rdist,
euclidean_dist_to_rdist, euclidean_rdist_to_dist)

cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def newObj(obj):

######################################################################
# define the reverse mapping of VALID_METRICS
from .dist_metrics import get_valid_metric_ids
from ._dist_metrics import get_valid_metric_ids
VALID_METRIC_IDS = get_valid_metric_ids(VALID_METRICS)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..utils.validation import _is_arraylike, _num_samples

import warnings
from .base import \
from ._base import \
_check_weights, _get_weights, \
NeighborsBase, KNeighborsMixin,\
RadiusNeighborsMixin, SupervisedIntegerMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ cimport cython
cimport numpy as np
from libc.math cimport fabs, sqrt, exp, cos, pow

from .typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t
from .typedefs import DTYPE, ITYPE
from ._typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t
from ._typedefs import DTYPE, ITYPE

######################################################################
# Inline distance functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ cdef inline np.ndarray _buffer_to_ndarray(DTYPE_t* x, np.npy_intp n):
from libc.math cimport fabs, sqrt, exp, pow, cos, sin, asin
cdef DTYPE_t INF = np.inf

from .typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t, DTYPECODE
from .typedefs import DTYPE, ITYPE
from ._typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t, DTYPECODE
from ._typedefs import DTYPE, ITYPE


######################################################################
Expand Down
8 changes: 4 additions & 4 deletions sklearn/neighbors/graph.py → sklearn/neighbors/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Tom Dupre la Tour
#
# License: BSD 3 clause (C) INRIA, University of Amsterdam
from .base import KNeighborsMixin, RadiusNeighborsMixin
from .base import NeighborsBase
from .base import UnsupervisedMixin
from .unsupervised import NearestNeighbors
from ._base import KNeighborsMixin, RadiusNeighborsMixin
from ._base import NeighborsBase
from ._base import UnsupervisedMixin
from ._unsupervised import NearestNeighbors
from ..base import TransformerMixin
from ..utils.validation import check_is_fitted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VALID_METRICS = ['EuclideanDistance', 'ManhattanDistance',
'ChebyshevDistance', 'MinkowskiDistance']


include "binary_tree.pxi"
include "_binary_tree.pxi"

# Inherit KDTree from BinaryTree
cdef class KDTree(BinaryTree):
Expand Down
4 changes: 2 additions & 2 deletions sklearn/neighbors/kde.py → sklearn/neighbors/_kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from ..utils import check_array, check_random_state, check_consistent_length

from ..utils.extmath import row_norms
from .ball_tree import BallTree, DTYPE
from .kd_tree import KDTree
from ._ball_tree import BallTree, DTYPE
from ._kd_tree import KDTree


VALID_KERNELS = ['gaussian', 'tophat', 'epanechnikov', 'exponential', 'linear',
Expand Down
6 changes: 3 additions & 3 deletions sklearn/neighbors/lof.py → sklearn/neighbors/_lof.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import numpy as np
import warnings

from .base import NeighborsBase
from .base import KNeighborsMixin
from .base import UnsupervisedMixin
from ._base import NeighborsBase
from ._base import KNeighborsMixin
from ._base import UnsupervisedMixin
from ..base import OutlierMixin

from ..utils.validation import check_is_fitted
Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/nca.py → sklearn/neighbors/_nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class NeighborhoodComponentsAnalysis(TransformerMixin, BaseEstimator):

Examples
--------
>>> from sklearn.neighbors.nca import NeighborhoodComponentsAnalysis
>>> from sklearn.neighbors import NeighborhoodComponentsAnalysis
>>> from sklearn.neighbors import KNeighborsClassifier
>>> from sklearn.datasets import load_iris
>>> from sklearn.model_selection import train_test_split
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NearestCentroid(ClassifierMixin, BaseEstimator):

Examples
--------
>>> from sklearn.neighbors.nearest_centroid import NearestCentroid
>>> from sklearn.neighbors import NearestCentroid
>>> import numpy as np
>>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> y = np.array([1, 1, 1, 2, 2, 2])
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import numpy as np

from .base import _get_weights, _check_weights, NeighborsBase, KNeighborsMixin
from .base import RadiusNeighborsMixin, SupervisedFloatMixin
from ._base import _get_weights, _check_weights, NeighborsBase, KNeighborsMixin
from ._base import RadiusNeighborsMixin, SupervisedFloatMixin
from ..base import RegressorMixin
from ..utils import check_array

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Unsupervised nearest neighbors learner"""
from .base import NeighborsBase
from .base import KNeighborsMixin
from .base import RadiusNeighborsMixin
from .base import UnsupervisedMixin
from ._base import NeighborsBase
from ._base import KNeighborsMixin
from ._base import RadiusNeighborsMixin
from ._base import UnsupervisedMixin


class NearestNeighbors(NeighborsBase, KNeighborsMixin,
Expand Down
20 changes: 10 additions & 10 deletions sklearn/neighbors/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ def configuration(parent_package='', top_path=None):
if os.name == 'posix':
libraries.append('m')

config.add_extension('ball_tree',
sources=['ball_tree.pyx'],
config.add_extension('_ball_tree',
sources=['_ball_tree.pyx'],
include_dirs=[numpy.get_include()],
libraries=libraries)

config.add_extension('kd_tree',
sources=['kd_tree.pyx'],
config.add_extension('_kd_tree',
sources=['_kd_tree.pyx'],
include_dirs=[numpy.get_include()],
libraries=libraries)

config.add_extension('dist_metrics',
sources=['dist_metrics.pyx'],
config.add_extension('_dist_metrics',
sources=['_dist_metrics.pyx'],
include_dirs=[numpy.get_include(),
os.path.join(numpy.get_include(),
'numpy')],
libraries=libraries)

config.add_extension('typedefs',
sources=['typedefs.pyx'],
config.add_extension('_typedefs',
sources=['_typedefs.pyx'],
include_dirs=[numpy.get_include()],
libraries=libraries)
config.add_extension("quad_tree",
sources=["quad_tree.pyx"],
config.add_extension("_quad_tree",
sources=["_quad_tree.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries)

Expand Down
8 changes: 4 additions & 4 deletions sklearn/neighbors/tests/test_ball_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import pytest
from numpy.testing import assert_array_almost_equal
from sklearn.neighbors.ball_tree import (BallTree, NeighborsHeap,
simultaneous_sort, kernel_norm,
nodeheap_sort, DTYPE, ITYPE)
from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors._ball_tree import (BallTree, NeighborsHeap,
simultaneous_sort, kernel_norm,
nodeheap_sort, DTYPE, ITYPE)
from sklearn.neighbors import DistanceMetric
from sklearn.utils import check_random_state
from sklearn.utils.testing import assert_allclose

Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/tests/test_dist_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from distutils.version import LooseVersion
from scipy import __version__ as scipy_version
from scipy.spatial.distance import cdist
from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors import DistanceMetric
from sklearn.neighbors import BallTree
from sklearn.utils import check_random_state
from sklearn.utils.testing import assert_raises_regex
Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sklearn.metrics import euclidean_distances
from sklearn.neighbors import KNeighborsTransformer, RadiusNeighborsTransformer
from sklearn.neighbors.base import _is_sorted_by_data
from sklearn.neighbors._base import _is_sorted_by_data


def test_transformer_result():
Expand Down
8 changes: 4 additions & 4 deletions sklearn/neighbors/tests/test_kd_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import pytest

from sklearn.neighbors.kd_tree import (KDTree, NeighborsHeap,
simultaneous_sort, kernel_norm,
nodeheap_sort, DTYPE, ITYPE)
from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors._kd_tree import (KDTree, NeighborsHeap,
simultaneous_sort, kernel_norm,
nodeheap_sort, DTYPE, ITYPE)
from sklearn.neighbors import DistanceMetric
from sklearn.utils import check_random_state
from sklearn.utils.testing import assert_allclose

Expand Down
Loading