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

`_transform_selected` ignores copy parameter when selected='all' #7194

Closed
caioaao opened this Issue Aug 16, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@caioaao
Contributor

caioaao commented Aug 16, 2016

Description

On this function, as the call for check_array is after the check for selected == 'all', so X is passed to the transform function without being copied. Is this the expected behavior? I'd expect the X received by transform function to be a copy of the original X when copy=False.

Steps/Code to Reproduce

import numpy as np
from sklearn.preprocessing.data import _transform_selected

def transform(X):
    X[0, 0] = X[0, 0] + 2
    return X

X = np.asarray([[1, 2], [3, 4]])
X2 = _transform_selected(X, transform, selected='all', copy=True)

print X
print X2

Prints:

Expected Results

To print

[[1 2]
 [3 4]]
[[3 2]
 [3 4]]

Actual Results

Prints

[[3 2]
 [3 4]]
[[3 2]
 [3 4]]

Versions

Linux-4.4.15-moby-x86_64-with-debian-7.4
('Python', '2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:08:32) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]')
('NumPy', '1.11.1')
('SciPy', '0.18.0')
('Scikit-Learn', '0.17.1')

caioaao added a commit to caioaao/scikit-learn that referenced this issue Aug 16, 2016

@jnothman

This comment has been minimized.

Member

jnothman commented Aug 17, 2016

Thanks. Your patch looks decent. Could you add a test and submit a pull request? Let us know if you need help with that.

@jnothman jnothman added this to the 0.18 milestone Aug 17, 2016

@jnothman jnothman added the Bug label Aug 17, 2016

agramfort added a commit that referenced this issue Aug 18, 2016

[MRG+1] Fix for "_transform_selected" not copying when "selected='all…
…'" (#7201)

* fixes issue #7194

* Added test

* Making `selected='all'` explicit on test

* Updated whats_new.rst

* Fixed typo on `whats_new.rst`

TomDLT added a commit to TomDLT/scikit-learn that referenced this issue Oct 3, 2016

[MRG+1] Fix for "_transform_selected" not copying when "selected='all…
…'" (scikit-learn#7201)

* fixes issue scikit-learn#7194

* Added test

* Making `selected='all'` explicit on test

* Updated whats_new.rst

* Fixed typo on `whats_new.rst`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment