@@ -773,8 +773,7 @@ def droplevel(self: FrameOrSeries, level, axis=0) -> FrameOrSeries:
773
773
"""
774
774
labels = self ._get_axis (axis )
775
775
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 )
778
777
779
778
def pop (self , item : Hashable ) -> Union [Series , Any ]:
780
779
result = self [item ]
@@ -1445,8 +1444,7 @@ def __invert__(self):
1445
1444
return self
1446
1445
1447
1446
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__" )
1450
1448
1451
1449
@final
1452
1450
def __nonzero__ (self ):
@@ -2036,8 +2034,7 @@ def _repr_data_resource_(self):
2036
2034
2037
2035
as_json = data .to_json (orient = "table" )
2038
2036
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 )
2041
2038
2042
2039
# ----------------------------------------------------------------------
2043
2040
# I/O Methods
@@ -5342,11 +5339,11 @@ def sample(
5342
5339
"Replace has to be set to `True` when "
5343
5340
"upsampling the population `frac` > 1."
5344
5341
)
5345
- elif n is not None and frac is None and n % 1 != 0 :
5342
+ elif frac is None and n % 1 != 0 :
5346
5343
raise ValueError ("Only integers accepted as `n` values" )
5347
5344
elif n is None and frac is not None :
5348
5345
n = round (frac * axis_length )
5349
- elif n is not None and frac is not None :
5346
+ elif frac is not None :
5350
5347
raise ValueError ("Please enter a value for `frac` OR `n`, not both" )
5351
5348
5352
5349
# Check for negative sizes
@@ -5467,15 +5464,13 @@ def __getattr__(self, name: str):
5467
5464
# Note: obj.x will always call obj.__getattribute__('x') prior to
5468
5465
# calling obj.__getattr__('x').
5469
5466
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 )
5473
5471
):
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 )
5479
5474
5480
5475
def __setattr__ (self , name : str , value ) -> None :
5481
5476
"""
@@ -5585,17 +5580,16 @@ def _is_mixed_type(self) -> bool_t:
5585
5580
@final
5586
5581
def _check_inplace_setting (self , value ) -> bool_t :
5587
5582
""" 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 :
5590
5584
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
5594
5588
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
+ )
5599
5593
5600
5594
return True
5601
5595
@@ -6264,8 +6258,7 @@ def convert_dtypes(
6264
6258
)
6265
6259
for col_name , col in self .items ()
6266
6260
]
6267
- result = concat (results , axis = 1 , copy = False )
6268
- return result
6261
+ return concat (results , axis = 1 , copy = False )
6269
6262
6270
6263
# ----------------------------------------------------------------------
6271
6264
# Filling NA's
@@ -7443,9 +7436,13 @@ def clip(
7443
7436
upper = None
7444
7437
7445
7438
# GH 2747 (arguments were reversed)
7446
- if lower is not None and upper is not None :
7447
- if is_scalar (lower ) and is_scalar (upper ):
7448
- lower , upper = min (lower , upper ), max (lower , upper )
7439
+ if (
7440
+ lower is not None
7441
+ and upper is not None
7442
+ and is_scalar (lower )
7443
+ and is_scalar (upper )
7444
+ ):
7445
+ lower , upper = min (lower , upper ), max (lower , upper )
7449
7446
7450
7447
# fast-path for scalars
7451
7448
if (lower is None or (is_scalar (lower ) and is_number (lower ))) and (
@@ -8234,10 +8231,9 @@ def first(self: FrameOrSeries, offset) -> FrameOrSeries:
8234
8231
end_date = end = self .index [0 ] + offset
8235
8232
8236
8233
# Tick-like, e.g. 3 weeks
8237
- if isinstance (offset , Tick ):
8238
- if end_date in self .index :
8239
- end = self .index .searchsorted (end_date , side = "left" )
8240
- return self .iloc [:end ]
8234
+ if isinstance (offset , Tick ) and end_date in self .index :
8235
+ end = self .index .searchsorted (end_date , side = "left" )
8236
+ return self .iloc [:end ]
8241
8237
8242
8238
return self .loc [:end ]
8243
8239
@@ -8646,17 +8642,19 @@ def _align_frame(
8646
8642
8647
8643
is_series = isinstance (self , ABCSeries )
8648
8644
8649
- if axis is None or axis == 0 :
8650
- if not self .index .equals (other .index ):
8651
- join_index , ilidx , iridx = self .index .join (
8652
- other .index , how = join , level = level , return_indexers = True
8653
- )
8645
+ if (axis is None or axis == 0 ) and not self .index .equals (other .index ):
8646
+ join_index , ilidx , iridx = self .index .join (
8647
+ other .index , how = join , level = level , return_indexers = True
8648
+ )
8654
8649
8655
- if axis is None or axis == 1 :
8656
- if not is_series and not self .columns .equals (other .columns ):
8657
- join_columns , clidx , cridx = self .columns .join (
8658
- other .columns , how = join , level = level , return_indexers = True
8659
- )
8650
+ if (
8651
+ (axis is None or axis == 1 )
8652
+ and not is_series
8653
+ and not self .columns .equals (other .columns )
8654
+ ):
8655
+ join_columns , clidx , cridx = self .columns .join (
8656
+ other .columns , how = join , level = level , return_indexers = True
8657
+ )
8660
8658
8661
8659
if is_series :
8662
8660
reindexers = {0 : [join_index , ilidx ]}
@@ -9524,9 +9522,8 @@ def truncate(
9524
9522
before = to_datetime (before )
9525
9523
after = to_datetime (after )
9526
9524
9527
- if before is not None and after is not None :
9528
- if before > after :
9529
- raise ValueError (f"Truncate: { after } must be after { before } " )
9525
+ if before is not None and after is not None and before > after :
9526
+ raise ValueError (f"Truncate: { after } must be after { before } " )
9530
9527
9531
9528
if len (ax ) > 1 and ax .is_monotonic_decreasing :
9532
9529
before , after = after , before
0 commit comments