@@ -381,34 +381,36 @@ def _calculate_inverse_indices(self, X):
381
381
Private function to calcuate indicies for inverse_transform
382
382
"""
383
383
# checks for overlap
384
- all_indexes = set ()
384
+ all_indices = set ()
385
385
input_indices = []
386
386
for name , trans , cols in self .transformers :
387
387
col_indices = _get_column_indices (X , cols )
388
388
col_indices_set = set (col_indices )
389
- if not all_indexes .isdisjoint (col_indices_set ):
390
- self ._invert_error = ("Unable to invert: transformers "
391
- " contain overlaping columns" )
389
+ if not all_indices .isdisjoint (col_indices_set ):
390
+ self ._invert_error = (
391
+ "transformers contain overlapping columns" )
392
392
return
393
393
if trans == 'drop' :
394
- self ._invert_error = "'{}' drops columns" .format (name )
394
+ self ._invert_error = ("dropping columns is not supported. "
395
+ "'{}' drops columns" .format (name ))
395
396
return
396
397
input_indices .append (col_indices )
397
- all_indexes .update (col_indices_set )
398
+ all_indices .update (col_indices_set )
398
399
399
400
# check remainder
400
401
remainder_indices = self ._remainder .indices
401
402
if (remainder_indices is not None
402
403
and self ._remainder .transformer == 'drop' ):
403
- self ._invert_error = "remainder drops columns"
404
+ self ._invert_error = ("dropping columns is not supported. "
405
+ "remainder drops columns" )
404
406
return
405
407
406
408
if remainder_indices is not None :
407
409
input_indices .append (remainder_indices )
408
410
409
411
self ._input_indices = input_indices
410
412
self ._n_features_in = X .shape [1 ]
411
- self ._X_columns = X . columns if hasattr (X , 'columns' ) else None
413
+ self ._X_columns = getattr (X , 'columns' , None )
412
414
self ._X_is_sparse = sparse .issparse (X )
413
415
self ._invert_error = ""
414
416
self ._output_indices = []
@@ -555,12 +557,12 @@ def inverse_transform(self, X):
555
557
trans = FunctionTransformer (
556
558
validate = False , accept_sparse = True , check_inverse = False )
557
559
558
- inv_transformers .append ((name , trans , sub , get_weight (name )))
560
+ inv_transformers .append ((trans , sub , get_weight (name )))
559
561
560
562
Xs = Parallel (n_jobs = self .n_jobs )(
561
563
delayed (_inverse_transform_one )(
562
564
trans , X_sel , weight )
563
- for _ , trans , X_sel , weight in inv_transformers )
565
+ for trans , X_sel , weight in inv_transformers )
564
566
565
567
if not Xs :
566
568
# All transformers are None
@@ -570,7 +572,7 @@ def inverse_transform(self, X):
570
572
inverse_Xs = sparse .lil_matrix ((Xs [0 ].shape [0 ],
571
573
self ._n_features_in ))
572
574
else :
573
- inverse_Xs = np .zeros ((Xs [0 ].shape [0 ], self ._n_features_in ))
575
+ inverse_Xs = np .empty ((Xs [0 ].shape [0 ], self ._n_features_in ))
574
576
for indices , inverse_X in zip (self ._input_indices , Xs ):
575
577
if sparse .issparse (inverse_X ):
576
578
if self ._X_is_sparse :
0 commit comments