(self, key)
| 943 | return out.__finalize__(self) |
| 944 | |
| 945 | def __getitem__(self, key): |
| 946 | check_dict_or_set_indexers(key) |
| 947 | key = com.apply_if_callable(key, self) |
| 948 | |
| 949 | if key is Ellipsis: |
| 950 | return self.copy(deep=False) |
| 951 | |
| 952 | key_is_scalar = is_scalar(key) |
| 953 | if isinstance(key, (list, tuple)): |
| 954 | key = unpack_1tuple(key) |
| 955 | |
| 956 | elif key_is_scalar: |
| 957 | # Note: GH#50617 in 3.0 we changed int key to always be treated as |
| 958 | # a label, matching DataFrame behavior. |
| 959 | return self._get_value(key) |
| 960 | |
| 961 | # Convert generator to list before going through hashable part |
| 962 | # (We will iterate through the generator there to check for slices) |
| 963 | if is_iterator(key): |
| 964 | key = list(key) |
| 965 | |
| 966 | if is_hashable(key, allow_slice=False): |
| 967 | # Otherwise index.get_value will raise InvalidIndexError |
| 968 | try: |
| 969 | # For labels that don't resolve as scalars like tuples and frozensets |
| 970 | result = self._get_value(key) |
| 971 | |
| 972 | return result |
| 973 | |
| 974 | except (KeyError, TypeError, InvalidIndexError): |
| 975 | # InvalidIndexError for e.g. generator |
| 976 | # see test_series_getitem_corner_generator |
| 977 | if isinstance(key, tuple) and isinstance(self.index, MultiIndex): |
| 978 | # We still have the corner case where a tuple is a key |
| 979 | # in the first level of our MultiIndex |
| 980 | return self._get_values_tuple(key) |
| 981 | |
| 982 | if isinstance(key, slice): |
| 983 | # Do slice check before somewhat-costly is_bool_indexer |
| 984 | return self._getitem_slice(key) |
| 985 | |
| 986 | if com.is_bool_indexer(key): |
| 987 | key = check_bool_indexer(self.index, key) |
| 988 | key = np.asarray(key, dtype=bool) |
| 989 | return self._get_rows_with_mask(key) |
| 990 | |
| 991 | return self._get_with(key) |
| 992 | |
| 993 | def _get_with(self, key): |
| 994 | # other: fancy integer or otherwise |
nothing calls this directly
no test coverage detected