8000 FIX for early numpy where astype(..., copy=...) unavailable · rmurcek/scikit-learn@c530f5a · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c530f5a

Browse files
committed
FIX for early numpy where astype(..., copy=...) unavailable
1 parent 14b435c commit c530f5a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sklearn/preprocessing/imputation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ..utils import atleast2d_or_csr
1515
from ..utils import atleast2d_or_csc
1616
from ..utils import as_float_array
17+
from ..utils.fixes import astype
1718

1819
from ..externals import six
1920

@@ -248,7 +249,7 @@ def _sparse_fit(self, X, strategy, missing_values, axis):
248249
X.indptr[1:-1])
249250

250251
# astype necessary for bug in numpy.hsplit before v1.9
251-
columns = [col[mask.astype(bool, copy=False)]
252+
columns = [col[astype(mask, bool, copy=False)]
252253
for col, mask in zip(columns_all, mask_valids)]
253254

254255
# Median

sklearn/utils/fixes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ def divide(x1, x2, out=None, dtype=None):
8484
if out_orig is None and np.isscalar(x1):
8585
out = np.asscalar(out)
8686
return out
87+
88+
89+
try:
90+
np.array(5).astype(float, copy=False)
91+
except TypeError:
92+
# Compat where astype accepted no copy argument
93+
def astype(array, dtype, copy=True):
94+
if array.dtype == dtype:
95+
return array
96+
return array.astype(dtype)
97+
else:
98+
astype = np.ndarray.astype

0 commit comments

Comments
 (0)
0