Skip to content
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

KDTree example in docs produces DeprecationWarning #6906

Closed
weatherfrog opened this issue Jun 18, 2016 · 6 comments · Fixed by #6962
Closed

KDTree example in docs produces DeprecationWarning #6906

weatherfrog opened this issue Jun 18, 2016 · 6 comments · Fixed by #6962
Labels
Documentation Easy Well-defined and straightforward way to resolve

Comments

@weatherfrog
Copy link

weatherfrog commented Jun 18, 2016

The basic KDTree example from the docs produces a DeprecatioinWarning (tested with 0.17.1):

X = np.random.random((10, 3))  # 10 points in 3 dimensions
tree = KDTree(X, leaf_size=2)
dist, ind = tree.query(X[0], k=3)

==>

[...]/lib/python3.4/site-packages/sklearn/utils/validation.py:386: DeprecationWarning:
Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.
Reshape your data either using X.reshape(-1, 1) if your data has a single feature or
X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)

I'm not (yet) very familiar with scikit-learn. But doesn't it seem "wrong" to say "Passing 1d arrays as data is deprecated" when the X passed is actually 2d?

@weatherfrog
Copy link
Author

weatherfrog commented Jun 18, 2016

Oh, data refers to the first argument of query(), not to the input points. That makes sense, of course. I think that argument – which, according to docs, is an array of points to query – should be wrapped in a list then. That makes the DeprecationWarning go away:

dist, ind = tree.query([X[0]], k=3)

@jnothman
Copy link
Member

yes, wrapping in a list being much like X.reshape(1, -1)

@weatherfrog
Copy link
Author

My point was: the docs should probably be updated. :-)

@jnothman
Copy link
Member

You're right. Sorry :/

@jnothman jnothman reopened this Jun 18, 2016
@jnothman
Copy link
Member

Feel free to submit a PR fixing sklearn/neighbors/binary_tree.pxi

@jnothman
Copy link
Member

It might also be interesting to try creating doctest fixtures that raise warnings as exceptions.

@jnothman jnothman added Easy Well-defined and straightforward way to resolve Documentation labels Jun 20, 2016
jannab added a commit to jannab/scikit-learn that referenced this issue Jul 6, 2016
- fill in missing import statement of sklearn.neighbors.KDTree
- wrap X in a list

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906
jannab added a commit to jannab/scikit-learn that referenced this issue Jul 8, 2016
- remove import statement of sklearn.neighbors.KDTree

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906
agramfort pushed a commit that referenced this issue Jul 16, 2016
#6962)

* docs: Change example of KDTree to prevent DeprecationWarning

- fill in missing import statement of sklearn.neighbors.KDTree
- wrap X in a list

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: #6906

* docs: remove import statement of KDTree in example of KDTree

- remove import statement of sklearn.neighbors.KDTree

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: #6906
olologin pushed a commit to olologin/scikit-learn that referenced this issue Aug 24, 2016
scikit-learn#6962)

* docs: Change example of KDTree to prevent DeprecationWarning

- fill in missing import statement of sklearn.neighbors.KDTree
- wrap X in a list

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906

* docs: remove import statement of KDTree in example of KDTree

- remove import statement of sklearn.neighbors.KDTree

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906
TomDLT pushed a commit to TomDLT/scikit-learn that referenced this issue Oct 3, 2016
scikit-learn#6962)

* docs: Change example of KDTree to prevent DeprecationWarning

- fill in missing import statement of sklearn.neighbors.KDTree
- wrap X in a list

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906

* docs: remove import statement of KDTree in example of KDTree

- remove import statement of sklearn.neighbors.KDTree

Changes to be committed:
	modified:   sklearn/neighbors/binary_tree.pxi

Resolves: scikit-learn#6906
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Easy Well-defined and straightforward way to resolve
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants