Construct an appropriately-labelled Series from the result of an op. Parameters ---------- result : ndarray or ExtensionArray name : Label other : Series, DataFrame or array-like Returns ------- Series In the case
(
self,
result: ArrayLike | tuple[ArrayLike, ArrayLike],
name: Hashable,
other: AnyArrayLike | DataFrame,
)
| 6811 | return cast(Series, out) |
| 6812 | |
| 6813 | def _construct_result( |
| 6814 | self, |
| 6815 | result: ArrayLike | tuple[ArrayLike, ArrayLike], |
| 6816 | name: Hashable, |
| 6817 | other: AnyArrayLike | DataFrame, |
| 6818 | ) -> Series | tuple[Series, Series]: |
| 6819 | """ |
| 6820 | Construct an appropriately-labelled Series from the result of an op. |
| 6821 | |
| 6822 | Parameters |
| 6823 | ---------- |
| 6824 | result : ndarray or ExtensionArray |
| 6825 | name : Label |
| 6826 | other : Series, DataFrame or array-like |
| 6827 | |
| 6828 | Returns |
| 6829 | ------- |
| 6830 | Series |
| 6831 | In the case of __divmod__ or __rdivmod__, a 2-tuple of Series. |
| 6832 | """ |
| 6833 | if isinstance(result, tuple): |
| 6834 | # produced by divmod or rdivmod |
| 6835 | |
| 6836 | res1 = self._construct_result(result[0], name=name, other=other) |
| 6837 | res2 = self._construct_result(result[1], name=name, other=other) |
| 6838 | |
| 6839 | # GH#33427 assertions to keep mypy happy |
| 6840 | assert isinstance(res1, Series) |
| 6841 | assert isinstance(res2, Series) |
| 6842 | return (res1, res2) |
| 6843 | |
| 6844 | # TODO: result should always be ArrayLike, but this fails for some |
| 6845 | # JSONArray tests |
| 6846 | dtype = getattr(result, "dtype", None) |
| 6847 | out = self._constructor(result, index=self.index, dtype=dtype, copy=False) |
| 6848 | out = out.__finalize__(self) |
| 6849 | out = out.__finalize__(other) |
| 6850 | |
| 6851 | # Set the result's name after __finalize__ is called because __finalize__ |
| 6852 | # would set it back to self.name |
| 6853 | out.name = name |
| 6854 | return out |
| 6855 | |
| 6856 | def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0): |
| 6857 | if axis is not None: |
no test coverage detected