@@ -304,8 +304,8 @@ def n_values_(self):
304
304
return self ._n_values_
305
305
306
306
def _handle_deprecations (self , X ):
307
-
308
307
# internal version of the attributes to handle deprecations
308
+ self ._n_values = self .n_values
309
309
self ._categories = getattr (self , '_categories' , None )
310
310
self ._categorical_features = getattr (self , '_categorical_features' ,
311
311
None )
@@ -362,7 +362,7 @@ def _handle_deprecations(self, X):
362
362
)
363
363
warnings .warn (msg , FutureWarning )
364
364
self ._legacy_mode = True
365
- self .n_values = 'auto'
365
+ self ._n_values = 'auto'
366
366
367
367
# if user specified categorical_features -> always use legacy mode
368
368
if self .categorical_features is not None :
@@ -427,18 +427,18 @@ def _legacy_fit_transform(self, X):
427
427
"be able to use arbitrary integer values as "
428
428
"category identifiers." )
429
429
n_samples , n_features = X .shape
430
- if (isinstance (self .n_values , six .string_types ) and
431
- self .n_values == 'auto' ):
430
+ if (isinstance (self ._n_values , six .string_types ) and
431
+ self ._n_values == 'auto' ):
432
432
n_values = np .max (X , axis = 0 ) + 1
433
- elif isinstance (self .n_values , numbers .Integral ):
434
- if (np .max (X , axis = 0 ) >= self .n_values ).any ():
433
+ elif isinstance (self ._n_values , numbers .Integral ):
434
+ if (np .max (X , axis = 0 ) >= self ._n_values ).any ():
435
435
raise ValueError ("Feature out of bounds for n_values=%d"
436
- % self .n_values )
436
+ % self ._n_values )
437
437
n_values = np .empty (n_features , dtype = np .int )
438
- n_values .fill (self .n_values )
438
+ n_values .fill (self ._n_values )
439
439
else :
440
440
try :
441
- n_values = np .asarray (self .n_values , dtype = int )
441
+ n_values = np .asarray (self ._n_values , dtype = int )
442
442
except (ValueError , TypeError ):
443
443
raise TypeError ("Wrong type for parameter `n_values`. Expected"
444
444
" 'auto', int or array of ints, got %r"
@@ -462,8 +462,8 @@ def _legacy_fit_transform(self, X):
462
462
shape = (n_samples , indices [- 1 ]),
463
463
dtype = self .dtype ).tocsr ()
464
464
465
- if (isinstance (self .n_values , six .string_types ) and
466
- self .n_values == 'auto' ):
465
+ if (isinstance (self ._n_values , six .string_types ) and
466
+ self ._n_values == 'auto' ):
467
467
mask = np .array (out .sum (axis = 0 )).ravel () != 0
468
468
active_features = np .where (mask )[0 ]
469
469
out = out [:, active_features ]
@@ -542,8 +542,8 @@ def _legacy_transform(self, X):
542
542
out = sparse .coo_matrix ((data , (row_indices , column_indices )),
543
543
shape = (n_samples , indices [- 1 ]),
544
544
dtype = self .dtype ).tocsr ()
545
- if (isinstance (self .n_values , six .string_types ) and
546
- self .n_values == 'auto' ):
545
+ if (isinstance (self ._n_values , six .string_types ) and
546
+ self ._n_values == 'auto' ):
547
547
out = out [:, self ._active_features_ ]
548
548
549
549
return out if self .sparse else out .toarray ()
0 commit comments