(self)
| 2949 | to_coord = utils.alias(to_index_variable, "to_coord") |
| 2950 | |
| 2951 | def _to_index(self) -> pd.Index: |
| 2952 | # n.b. creating a new pandas.Index from an old pandas.Index is |
| 2953 | # basically free as pandas.Index objects are immutable. |
| 2954 | # n.b.2. this method returns the multi-index instance for |
| 2955 | # a pandas multi-index level variable. |
| 2956 | assert self.ndim == 1 |
| 2957 | index = self._data.array |
| 2958 | if isinstance(index, pd.MultiIndex): |
| 2959 | # set default names for multi-index unnamed levels so that |
| 2960 | # we can safely rename dimension / coordinate later |
| 2961 | valid_level_names = [ |
| 2962 | name or f"{self.dims[0]}_level_{i}" |
| 2963 | for i, name in enumerate(index.names) |
| 2964 | ] |
| 2965 | index = index.set_names(valid_level_names) |
| 2966 | else: |
| 2967 | index = index.set_names(self.name) |
| 2968 | return index |
| 2969 | |
| 2970 | def to_index(self) -> pd.Index: |
| 2971 | """Convert this variable to a pandas.Index""" |
no outgoing calls
no test coverage detected