@@ -907,9 +907,7 @@ def __repr__(self) -> str_t:
907
907
if data is None :
908
908
data = ""
909
909
910
- res = f"{ klass_name } ({ data } { prepr } )"
911
-
912
- return res
910
+ return f"{ klass_name } ({ data } { prepr } )"
913
911
914
912
def _format_space (self ) -> str_t :
915
913
@@ -988,7 +986,6 @@ def _format_with_header(
988
986
if is_object_dtype (values .dtype ):
989
987
values = lib .maybe_convert_objects (values , safe = 1 )
990
988
991
- if is_object_dtype (values .dtype ):
992
989
result = [pprint_thing (x , escape_chars = ("\t " , "\r " , "\n " )) for x in values ]
993
990
994
991
# could have nans
@@ -1616,7 +1613,7 @@ def _drop_level_numbers(self, levnums: List[int]):
1616
1613
Drop MultiIndex levels by level _number_, not name.
1617
1614
"""
1618
1615
1619
- if len ( levnums ) == 0 :
1616
+ if not levnums :
1620
1617
return self
1621
1618
if len (levnums ) >= self .nlevels :
1622
1619
raise ValueError (
@@ -3154,7 +3151,7 @@ def _get_indexer(
3154
3151
target , method = method , limit = limit , tolerance = tolerance
3155
3152
)
3156
3153
3157
- if method == "pad" or method == "backfill" :
3154
+ if method in [ "pad" , "backfill" ] :
3158
3155
indexer = self ._get_fill_indexer (target , method , limit , tolerance )
3159
3156
elif method == "nearest" :
3160
3157
indexer = self ._get_nearest_indexer (target , limit , tolerance )
@@ -3295,8 +3292,7 @@ def _filter_indexer_tolerance(
3295
3292
) -> np .ndarray :
3296
3293
# error: Unsupported left operand type for - ("ExtensionArray")
3297
3294
distance = abs (self ._values [indexer ] - target ) # type: ignore[operator]
3298
- indexer = np .where (distance <= tolerance , indexer , - 1 )
3299
- return indexer
3295
+ return np .where (distance <= tolerance , indexer , - 1 )
3300
3296
3301
3297
# --------------------------------------------------------------------
3302
3298
# Indexer Conversion Methods
@@ -3426,8 +3422,7 @@ def _convert_arr_indexer(self, keyarr):
3426
3422
-------
3427
3423
converted_keyarr : array-like
3428
3424
"""
3429
- keyarr = com .asarray_tuplesafe (keyarr )
3430
- return keyarr
3425
+ return com .asarray_tuplesafe (keyarr )
3431
3426
3432
3427
def _convert_list_indexer (self , keyarr ):
3433
3428
"""
@@ -3795,9 +3790,8 @@ def _join_multi(self, other, how, return_indexers=True):
3795
3790
other , level , how = how , return_indexers = return_indexers
3796
3791
)
3797
3792
3798
- if flip_order :
3799
- if isinstance (result , tuple ):
3800
- return result [0 ], result [2 ], result [1 ]
3793
+ if flip_order and isinstance (result , tuple ):
3794
+ return result [0 ], result [2 ], result [1 ]
3801
3795
return result
3802
3796
3803
3797
@final
@@ -4329,7 +4323,7 @@ def append(self, other):
4329
4323
to_concat = [self ]
4330
4324
4331
4325
if isinstance (other , (list , tuple )):
4332
- to_concat = to_concat + list (other )
4326
+ to_concat += list (other )
4333
4327
else :
4334
4328
to_concat .append (other )
4335
4329
@@ -4821,9 +4815,7 @@ def _should_fallback_to_positional(self) -> bool:
4821
4815
"""
4822
4816
Should an integer key be treated as positional?
4823
4817
"""
4824
- if self .holds_integer () or self .is_boolean ():
4825
- return False
4826
- return True
4818
+ return not self .holds_integer () and not self .is_boolean ()
4827
4819
4828
4820
def _get_values_for_loc (self , series : "Series" , loc , key ):
4829
4821
"""
@@ -5286,11 +5278,7 @@ def _validate_indexer(self, form: str_t, key, kind: str_t):
5286
5278
"""
5287
5279
assert kind in ["getitem" , "iloc" ]
5288
5280
5289
- if key is None :
5290
- pass
5291
- elif is_integer (key ):
5292
- pass
5293
- else :
5281
+ if key is not None and not is_integer (key ):
5294
5282
raise self ._invalid_indexer (form , key )
5295
5283
5296
5284
def _maybe_cast_slice_bound (self , label , side : str_t , kind ):
@@ -5609,9 +5597,10 @@ def _cmp_method(self, other, op):
5609
5597
elif op in {operator .ne , operator .lt , operator .gt }:
5610
5598
return np .zeros (len (self ), dtype = bool )
5611
5599
5612
- if isinstance (other , (np .ndarray , Index , ABCSeries , ExtensionArray )):
5613
- if len (self ) != len (other ):
5614
- raise ValueError ("Lengths must match to compare" )
5600
+ if isinstance (other , (np .ndarray , Index , ABCSeries , ExtensionArray )) and len (
5601
+ self
5602
+ ) != len (other ):
5603
+ raise ValueError ("Lengths must match to compare" )
5615
5604
5616
5605
if not isinstance (other , ABCMultiIndex ):
5617
5606
other = extract_array (other , extract_numpy = True )
@@ -5931,11 +5920,20 @@ def ensure_has_len(seq):
5931
5920
def trim_front (strings : List [str ]) -> List [str ]:
5932
5921
"""
5933
5922
Trims zeros and decimal points.
5923
+
5924
+ Examples
5925
+ --------
5926
+ >>> trim_front([" a", " b"])
5927
+ ['a', 'b']
5928
+
5929
+ >>> trim_front([" a", " "])
5930
+ ['a', '']
5934
5931
"""
5935
- trimmed = strings
5936
- while len (strings ) > 0 and all (x [0 ] == " " for x in trimmed ):
5937
- trimmed = [x [1 :] for x in trimmed ]
5938
- return trimmed
5932
+ if not strings :
5933
+ return strings
5934
+ while all (strings ) and all (x [0 ] == " " for x in strings ):
5935
+ strings = [x [1 :] for x in strings ]
5936
+ return strings
5939
5937
5940
5938
5941
5939
def _validate_join_method (method : str ):
@@ -6003,15 +6001,11 @@ def _maybe_cast_with_dtype(data: np.ndarray, dtype: np.dtype, copy: bool) -> np.
6003
6001
except ValueError :
6004
6002
data = np .array (data , dtype = np .float64 , copy = copy )
6005
6003
6006
- elif inferred == "string" :
6007
- pass
6008
- else :
6004
+ elif inferred != "string" :
6009
6005
data = data .astype (dtype )
6010
6006
elif is_float_dtype (dtype ):
6011
6007
inferred = lib .infer_dtype (data , skipna = False )
6012
- if inferred == "string" :
6013
- pass
6014
- else :
6008
+ if inferred != "string" :
6015
6009
data = data .astype (dtype )
6016
6010
else :
6017
6011
data = np .array (data , dtype = dtype , copy = copy )
0 commit comments