Ensure that if we don't have an index, that we can create one from the passed value.
(self, value)
| 4931 | ) from ii_err |
| 4932 | |
| 4933 | def _ensure_valid_index(self, value) -> None: |
| 4934 | """ |
| 4935 | Ensure that if we don't have an index, that we can create one from the |
| 4936 | passed value. |
| 4937 | """ |
| 4938 | # GH5632, make sure that we are a Series convertible |
| 4939 | if not len(self.index) and is_list_like(value) and len(value): |
| 4940 | if not isinstance(value, DataFrame): |
| 4941 | try: |
| 4942 | value = Series(value) |
| 4943 | except (ValueError, NotImplementedError, TypeError) as err: |
| 4944 | raise ValueError( |
| 4945 | "Cannot set a frame with no defined index " |
| 4946 | "and a value that cannot be converted to a Series" |
| 4947 | ) from err |
| 4948 | |
| 4949 | # GH31368 preserve name of index |
| 4950 | index_copy = value.index.copy() |
| 4951 | if self.index.name is not None: |
| 4952 | index_copy.name = self.index.name |
| 4953 | |
| 4954 | self._mgr = self._mgr.reindex_axis(index_copy, axis=1, fill_value=np.nan) |
| 4955 | |
| 4956 | def _box_col_values(self, values: SingleBlockManager, loc: int) -> Series: |
| 4957 | """ |
no test coverage detected