@@ -773,8 +773,7 @@ def droplevel(self: FrameOrSeries, level, axis=0) -> FrameOrSeries:
773773 """
774774 labels = self ._get_axis (axis )
775775 new_labels = labels .droplevel (level )
776- result = self .set_axis (new_labels , axis = axis , inplace = False )
777- return result
776+ return self .set_axis (new_labels , axis = axis , inplace = False )
778777
779778 def pop (self , item : Hashable ) -> Union [Series , Any ]:
780779 result = self [item ]
@@ -1445,8 +1444,7 @@ def __invert__(self):
14451444 return self
14461445
14471446 new_data = self ._mgr .apply (operator .invert )
1448- result = self ._constructor (new_data ).__finalize__ (self , method = "__invert__" )
1449- return result
1447+ return self ._constructor (new_data ).__finalize__ (self , method = "__invert__" )
14501448
14511449 @final
14521450 def __nonzero__ (self ):
@@ -2036,8 +2034,7 @@ def _repr_data_resource_(self):
20362034
20372035 as_json = data .to_json (orient = "table" )
20382036 as_json = cast (str , as_json )
2039- payload = json .loads (as_json , object_pairs_hook = collections .OrderedDict )
2040- return payload
2037+ return json .loads (as_json , object_pairs_hook = collections .OrderedDict )
20412038
20422039 # ----------------------------------------------------------------------
20432040 # I/O Methods
@@ -5342,11 +5339,11 @@ def sample(
53425339 "Replace has to be set to `True` when "
53435340 "upsampling the population `frac` > 1."
53445341 )
5345- elif n is not None and frac is None and n % 1 != 0 :
5342+ elif frac is None and n % 1 != 0 :
53465343 raise ValueError ("Only integers accepted as `n` values" )
53475344 elif n is None and frac is not None :
53485345 n = round (frac * axis_length )
5349- elif n is not None and frac is not None :
5346+ elif frac is not None :
53505347 raise ValueError ("Please enter a value for `frac` OR `n`, not both" )
53515348
53525349 # Check for negative sizes
@@ -5467,15 +5464,13 @@ def __getattr__(self, name: str):
54675464 # Note: obj.x will always call obj.__getattribute__('x') prior to
54685465 # calling obj.__getattr__('x').
54695466 if (
5470- name in self ._internal_names_set
5471- or name in self ._metadata
5472- or name in self ._accessors
5467+ name not in self ._internal_names_set
5468+ and name not in self ._metadata
5469+ and name not in self ._accessors
5470+ and self ._info_axis ._can_hold_identifiers_and_holds_name (name )
54735471 ):
5474- return object .__getattribute__ (self , name )
5475- else :
5476- if self ._info_axis ._can_hold_identifiers_and_holds_name (name ):
5477- return self [name ]
5478- return object .__getattribute__ (self , name )
5472+ return self [name ]
5473+ return object .__getattribute__ (self , name )
54795474
54805475 def __setattr__ (self , name : str , value ) -> None :
54815476 """
@@ -5585,17 +5580,16 @@ def _is_mixed_type(self) -> bool_t:
55855580 @final
55865581 def _check_inplace_setting (self , value ) -> bool_t :
55875582 """ check whether we allow in-place setting with this type of value """
5588- if self ._is_mixed_type :
5589- if not self ._mgr .is_numeric_mixed_type :
5583+ if self ._is_mixed_type and not self ._mgr .is_numeric_mixed_type :
55905584
5591- # allow an actual np.nan thru
5592- if is_float (value ) and np .isnan (value ):
5593- return True
5585+ # allow an actual np.nan thru
5586+ if is_float (value ) and np .isnan (value ):
5587+ return True
55945588
5595- raise TypeError (
5596- "Cannot do inplace boolean setting on "
5597- "mixed-types with a non np.nan value"
5598- )
5589+ raise TypeError (
5590+ "Cannot do inplace boolean setting on "
5591+ "mixed-types with a non np.nan value"
5592+ )
55995593
56005594 return True
56015595
@@ -6265,8 +6259,7 @@ def convert_dtypes(
62656259 )
62666260 for col_name , col in self .items ()
62676261 ]
6268- result = concat (results , axis = 1 , copy = False )
6269- return result
6262+ return concat (results , axis = 1 , copy = False )
62706263
62716264 # ----------------------------------------------------------------------
62726265 # Filling NA's
@@ -7444,9 +7437,13 @@ def clip(
74447437 upper = None
74457438
74467439 # GH 2747 (arguments were reversed)
7447- if lower is not None and upper is not None :
7448- if is_scalar (lower ) and is_scalar (upper ):
7449- lower , upper = min (lower , upper ), max (lower , upper )
7440+ if (
7441+ lower is not None
7442+ and upper is not None
7443+ and is_scalar (lower )
7444+ and is_scalar (upper )
7445+ ):
7446+ lower , upper = min (lower , upper ), max (lower , upper )
74507447
74517448 # fast-path for scalars
74527449 if (lower is None or (is_scalar (lower ) and is_number (lower ))) and (
@@ -8235,10 +8232,9 @@ def first(self: FrameOrSeries, offset) -> FrameOrSeries:
82358232 end_date = end = self .index [0 ] + offset
82368233
82378234 # Tick-like, e.g. 3 weeks
8238- if isinstance (offset , Tick ):
8239- if end_date in self .index :
8240- end = self .index .searchsorted (end_date , side = "left" )
8241- return self .iloc [:end ]
8235+ if isinstance (offset , Tick ) and end_date in self .index :
8236+ end = self .index .searchsorted (end_date , side = "left" )
8237+ return self .iloc [:end ]
82428238
82438239 return self .loc [:end ]
82448240
@@ -8647,17 +8643,19 @@ def _align_frame(
86478643
86488644 is_series = isinstance (self , ABCSeries )
86498645
8650- if axis is None or axis == 0 :
8651- if not self .index .equals (other .index ):
8652- join_index , ilidx , iridx = self .index .join (
8653- other .index , how = join , level = level , return_indexers = True
8654- )
8646+ if (axis is None or axis == 0 ) and not self .index .equals (other .index ):
8647+ join_index , ilidx , iridx = self .index .join (
8648+ other .index , how = join , level = level , return_indexers = True
8649+ )
86558650
8656- if axis is None or axis == 1 :
8657- if not is_series and not self .columns .equals (other .columns ):
8658- join_columns , clidx , cridx = self .columns .join (
8659- other .columns , how = join , level = level , return_indexers = True
8660- )
8651+ if (
8652+ (axis is None or axis == 1 )
8653+ and not is_series
8654+ and not self .columns .equals (other .columns )
8655+ ):
8656+ join_columns , clidx , cridx = self .columns .join (
8657+ other .columns , how = join , level = level , return_indexers = True
8658+ )
86618659
86628660 if is_series :
86638661 reindexers = {0 : [join_index , ilidx ]}
@@ -9525,9 +9523,8 @@ def truncate(
95259523 before = to_datetime (before )
95269524 after = to_datetime (after )
95279525
9528- if before is not None and after is not None :
9529- if before > after :
9530- raise ValueError (f"Truncate: { after } must be after { before } " )
9526+ if before is not None and after is not None and before > after :
9527+ raise ValueError (f"Truncate: { after } must be after { before } " )
95319528
95329529 if len (ax ) > 1 and ax .is_monotonic_decreasing :
95339530 before , after = after , before
0 commit comments