52
52
from pandas .compat .numpy import function as nv
53
53
from pandas .compat import (map , zip , lzip , lrange , string_types ,
54
54
isidentifier , set_function_name , cPickle as pkl )
55
+ from pandas .core .ops import _align_method_FRAME
55
56
import pandas .core .nanops as nanops
56
57
from pandas .util ._decorators import Appender , Substitution , deprecate_kwarg
57
58
from pandas .util ._validators import validate_bool_kwarg
@@ -4415,6 +4416,8 @@ def _clip_with_scalar(self, lower, upper, inplace=False):
4415
4416
def _clip_with_one_bound (self , threshold , method , axis , inplace ):
4416
4417
4417
4418
inplace = validate_bool_kwarg (inplace , 'inplace' )
4419
+ if axis is not None :
4420
+ axis = self ._get_axis_number (axis )
4418
4421
4419
4422
if np .any (isnull (threshold )):
4420
4423
raise ValueError ("Cannot use an NA value as a clip threshold" )
@@ -4428,11 +4431,14 @@ def _clip_with_one_bound(self, threshold, method, axis, inplace):
4428
4431
subset = method (threshold , axis = axis ) | isnull (self )
4429
4432
4430
4433
# GH #15390
4434
+ # In order for where method to work, the threshold must
4435
+ # be transformed to NDFrame from other array like structure.
4431
4436
if (not isinstance (threshold , ABCSeries )) and is_list_like (threshold ):
4432
- if isinstance (self , ABCSeries ) or axis == 0 :
4437
+ if isinstance (self , ABCSeries ):
4433
4438
threshold = pd .Series (threshold , index = self .index )
4434
- elif axis == 1 :
4435
- threshold = pd .Series (threshold , index = self .columns )
4439
+ else :
4440
+ threshold = _align_method_FRAME (self , np .asarray (threshold ),
4441
+ axis )
4436
4442
return self .where (subset , threshold , axis = axis , inplace = inplace )
4437
4443
4438
4444
def clip (self , lower = None , upper = None , axis = None , inplace = False ,
0 commit comments