Skip to content

Commit bed8d34

Browse files
committed
dedent part of Series._get_with one level
1 parent ffae158 commit bed8d34

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

pandas/core/series.py

+35-36
Original file line numberDiff line numberDiff line change
@@ -828,47 +828,46 @@ def _get_with(self, key):
828828
elif isinstance(key, ABCDataFrame):
829829
raise TypeError('Indexing a Series with DataFrame is not '
830830
'supported, use the appropriate DataFrame column')
831-
else:
832-
if isinstance(key, tuple):
833-
try:
834-
return self._get_values_tuple(key)
835-
except Exception:
836-
if len(key) == 1:
837-
key = key[0]
838-
if isinstance(key, slice):
839-
return self._get_values(key)
840-
raise
831+
elif isinstance(key, tuple):
832+
try:
833+
return self._get_values_tuple(key)
834+
except Exception:
835+
if len(key) == 1:
836+
key = key[0]
837+
if isinstance(key, slice):
838+
return self._get_values(key)
839+
raise
841840

842-
# pragma: no cover
843-
if not isinstance(key, (list, np.ndarray, Series, Index)):
844-
key = list(key)
841+
# pragma: no cover
842+
if not isinstance(key, (list, np.ndarray, Series, Index)):
843+
key = list(key)
845844

846-
if isinstance(key, Index):
847-
key_type = key.inferred_type
848-
else:
849-
key_type = lib.infer_dtype(key)
845+
if isinstance(key, Index):
846+
key_type = key.inferred_type
847+
else:
848+
key_type = lib.infer_dtype(key)
850849

851-
if key_type == 'integer':
852-
if self.index.is_integer() or self.index.is_floating():
853-
return self.loc[key]
854-
else:
855-
return self._get_values(key)
856-
elif key_type == 'boolean':
857-
return self._get_values(key)
850+
if key_type == 'integer':
851+
if self.index.is_integer() or self.index.is_floating():
852+
return self.loc[key]
858853
else:
859-
try:
860-
# handle the dup indexing case (GH 4246)
861-
if isinstance(key, (list, tuple)):
862-
return self.loc[key]
854+
return self._get_values(key)
855+
elif key_type == 'boolean':
856+
return self._get_values(key)
857+
else:
858+
try:
859+
# handle the dup indexing case (GH 4246)
860+
if isinstance(key, (list, tuple)):
861+
return self.loc[key]
863862

864-
return self.reindex(key)
865-
except Exception:
866-
# [slice(0, 5, None)] will break if you convert to ndarray,
867-
# e.g. as requested by np.median
868-
# hack
869-
if isinstance(key[0], slice):
870-
return self._get_values(key)
871-
raise
863+
return self.reindex(key)
864+
except Exception:
865+
# [slice(0, 5, None)] will break if you convert to ndarray,
866+
# e.g. as requested by np.median
867+
# hack
868+
if isinstance(key[0], slice):
869+
return self._get_values(key)
870+
raise
872871

873872
def _get_values_tuple(self, key):
874873
# mpl hackaround

0 commit comments

Comments
 (0)