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
@@ -4416,6 +4417,8 @@ def _clip_with_scalar(self, lower, upper, inplace=False):
4416
4417
def _clip_with_one_bound (self , threshold , method , axis , inplace ):
4417
4418
4418
4419
inplace = validate_bool_kwarg (inplace , 'inplace' )
4420
+ if axis is not None :
4421
+ axis = self ._get_axis_number (axis )
4419
4422
4420
4423
if np .any (isnull (threshold )):
4421
4424
raise ValueError ("Cannot use an NA value as a clip threshold" )
@@ -4429,11 +4432,14 @@ def _clip_with_one_bound(self, threshold, method, axis, inplace):
4429
4432
subset = method (threshold , axis = axis ) | isnull (self )
4430
4433
4431
4434
# GH #15390
4435
+ # In order for where method to work, the threshold must
4436
+ # be transformed to NDFrame from other array like structure.
4432
4437
if (not isinstance (threshold , ABCSeries )) and is_list_like (threshold ):
4433
- if isinstance (self , ABCSeries ) or axis == 0 :
4438
+ if isinstance (self , ABCSeries ):
4434
4439
threshold = pd .Series (threshold , index = self .index )
4435
- elif axis == 1 :
4436
- threshold = pd .Series (threshold , index = self .columns )
4440
+ else :
4441
+ threshold = _align_method_FRAME (self , np .asarray (threshold ),
4442
+ axis )
4437
4443
return self .where (subset , threshold , axis = axis , inplace = inplace )
4438
4444
4439
4445
def clip (self , lower = None , upper = None , axis = None , inplace = False ,
0 commit comments